Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute URL

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
Hi,

I would like to execute a URL from a php file, that is to send an http request and get back the result. Any ideas?

thanxs,
alej
 
sorry but i cant find this thread :-(
 
Sorry, i got it, did not realize it was a FAQ. But the code there is only for CGI? because I need to perform an HTTP GET (need to retrieve some info from an ASP file). Thanxs!

cheers,
alej
 
Sorry, typo. FAQ434-2502

Provided you are running a fairly recent version of PHP and have the runtime configuration directive "allow_url_fopen" set to "on", GET-method is easy.

Given a PHP script on a server which reads:

test_show_get.php
Code:
<?php
print '<html><body><pre>';
print_r ($_GET);
print '</pre></body></html>';
?>

And a script on your server which reads:

test_do_get.php
Code:
<?php
$fh = fopen ('[URL unfurl="true"]http://www.foreignserver.com/test_show_get.php?var1=val1&var2=val2',[/URL] 'r');

while ($line = fgets ($fh))
{
	print $line;
}
?>

test_do_get.php returns:

[tt]<html><body><pre>Array
(
[var1] => val1
[var2] => val2
)
</pre></body></html>[/tt]


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top