PHP Proxy for getting other domain content
Can I write a PHP file (index.php) that when someone point it browser to
http://www.domain.org/some?params=a&b=1
it returns the content of
http://www.OTHERdomain.org/some?param开发者_StackOverflows=a&b=1
Should I use culr?
From http://www.php.net/manual/en/curl.examples-basic.php#88055, this is the code you need:
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
?>
You could create a page called proxy.php
or something like that that takes a URL as the parameter. Then, you can replace domain.org
with otherdomain.org
in the URL. Then use CURL to get the contents and return it.
精彩评论