php include to external url

后端 未结 5 1377
迷失自我
迷失自我 2020-12-19 15:29

I am currently trying to use the php function \'include\' to include an external url. This is so that whenever the webpage is updated it will automatically update mine. The

相关标签:
5条回答
  • 2020-12-19 15:40

    Look at your php.ini and make sure allow_url_include is set to 1. Restart HTTPD, done.

    0 讨论(0)
  • 2020-12-19 15:41

    You would be better using echo file_get_contents($url) as the include statement could execute any PHP code returned by the other site.

    0 讨论(0)
  • 2020-12-19 15:46

    Look at your php.ini and make sure allow_url_include is set to 1

    Otherwise use following ...

    function getter($url) 
    {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;}
    echo getter('http://yourdomain.com/externalfile.php');
    
    0 讨论(0)
  • 2020-12-19 15:51

    This will load an external website and also gives external links an absolute website link address

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.your_external_website.com");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.your_external_website.com/$2$3', $result);
    echo $result
    
    0 讨论(0)
  • 2020-12-19 15:52
    function getter($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    
    echo getter('http://yourdomain.com/externalfile.php');
    

    And you're done :)

    0 讨论(0)
提交回复
热议问题