0

I simply need to send data to a GET parameter on a different host but I fail to find a suitable function within PHP for that occasion. That's my only question.

For example send any value for the information parameter:

http://example.com/obtainer.php?information=

Thanks :)

Keeper
  • 37
  • 8

3 Answers3

0

Query strings (_GET) parameter are constructed like;

www.example.com/index.php?param1=value&param2=value

If you're sending any value to the information parameter via form, do the following;

<form action="" method="get">
 <input type="text" name="information" value="" />
 <input type="submit" value="Send" />
</form>

However, if you're sending the data via link, write it manually, like so;

<a href="index.php?information=hello">Link</a>

Remember, when putting string into the query string, ensure you use urlencode

sniko
  • 71
  • 5
  • Can you please read my question again? First of all I said it's on a different host and second I don't need a simple link but a php function.. – Keeper Aug 24 '13 at 00:12
  • I read it multiple times before submitting, and failed to see "different host" - my apologies. Simply change the `action` in the form, or the `href` link to the host. The term `host` do you mean another website, or multiple servers for one site? – sniko Aug 24 '13 at 00:15
  • On multiple backend servers, or a single server? If it's the latter, my example is fine, right? – sniko Aug 24 '13 at 00:21
  • Ok for the third time "I don't need a simple link but a php function.. " – Keeper Aug 24 '13 at 00:25
  • Have you looked into http://www.php.net/manual/en/function.http-build-query.php ? – sniko Aug 24 '13 at 00:29
0

I suppose you are sending something to http://example.com/obtainer.php, you can try the following PHP function...

file_get_contents('http://example.com/obtainer.php?information='.urlencode('whatever');
Aaron Gong
  • 977
  • 7
  • 18
0

It depends what you are trying to do. If you're trying to use an API for another website, than what you want is the file_get_contents function. For example:

<?php
$username = 'S1nus';
?>
<img src=<?php echo "'" . file_get_contents("http://psirup.com/api/getpsignature?user=$username") . "'";?>

would return this image (Maybe not the best example, but the simplest API I can think of). (Don't forget to urlencode() the parameter, I almost forgot).

However, you may want to use HttpRequest::send. This documentation explains how to use it with GETrequests.

  • "Don't forget to use urlencode, you failed to use it within your example – Daryl Gill Aug 24 '13 at 00:15
  • I think I should commit suicide.. Can any of you read or you are just here for the "lulz"? I DON'T NEED PECL FUNCTIONS OR FILE_GET_CONTENTS I NEED TO APPEND DATA TO AN EXTERNAL GET PARAMETER LOCATED ON A DIFFERENT WEBSITE – Keeper Aug 24 '13 at 00:24
  • Woa, calm down there buddy. You're not making any sense. Append data to an external get parameter? What in the world does that mean? You understand how GET data works, right? – user2712640 Aug 24 '13 at 04:21
  • The question is do you understand what it means? – Keeper Aug 24 '13 at 15:25