开发者

PHP Proxy for getting other domain content

开发者 https://www.devze.com 2023-01-14 04:31 出处:网络
Can I write a PHP file (index.php) that when someone point it browser to http://www.domain.org/some?params=a&b=1

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消