无法在生产网站上卷曲网站,只能在localhost中工作 - php

时间:2018-06-11 05:35:52

标签: javascript php

卷曲网站时遇到问题: http://hdonline.vn/phim-into-the-badlands-3-15477.html

这是真正的代码(它在localhost中工作):

<?php
    /**
     * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
     * array containing the HTTP server response header fields and content.
     */
    function get_web_page( $url )
    {
        $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';

        $options = array(

            CURLOPT_CUSTOMREQUEST  =>"GET",        //set request type post or get
            CURLOPT_POST           =>false,        //set to GET
            CURLOPT_USERAGENT      => $user_agent, //set user agent
            CURLOPT_COOKIEFILE     =>"cookie.txt", //set cookie file
            CURLOPT_COOKIEJAR      =>"cookie.txt", //set cookie jar
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
            CURLOPT_TIMEOUT        => 120,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        );

        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch );
        curl_close( $ch );

        $header['errno']   = $err;
        $header['errmsg']  = $errmsg;
        $header['content'] = $content;
        return $header;
    }
    $result = get_web_page('http://hdonline.vn/phim-into-the-badlands-3-15477.html');

    if ( $result['errno'] != 0 )
        echo 'lỗi';

    if ( $result['http_code'] != 200 )
        echo 'không có trang, ko có quyền';

    $page = $result['content'];
    print_r($page);
?>

您可以复制所有代码并创建要测试的新页面。

问题是:我将源代码上传到我的VPS,这里是生产站点: https://sharengay.com/hdonline/curlhdonline.php

它没有显示任何内容。

在localhost中:

https://sharengay.com/hdonline中:

我在第一个php文件中添加了此代码以传递:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

0 个答案:

没有答案