Jump to content

Open a URL server side with PHP


prosper99

Recommended Posts

Hello Everyone,

 

Looking for 2 methods to opening a non local url that is formed from a php script.

 

1st method is to open a URL on the local server where PHP is running,

2nd method is to open a URL on a remote PHP proxy server.

 

In both cases just need it to open and close.  Can PHP provide this functionality?

 

Thank You.

Rob.

 

Link to comment
https://forums.phpfreaks.com/topic/192311-open-a-url-server-side-with-php/
Share on other sites

Thank You, yes CURL works for me for opening URL's locally.  But can't seem to find any examples of CURL opening a URL on a remote PHP proxy, ie submit a url to the proxy and have it open it...

 

<?php

function get_data($url)

{

$ch = curl_init();

$timeout = 5;

$userAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";

curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

curl_setopt($ch, CURLOPT_FAILONERROR, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_AUTOREFERER, true);

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);

$data = curl_exec($ch);

curl_close($ch);

return $data;

}

$returned_content = get_data('http://anyphpproxy.com');

echo $returned_content;

?>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.