PHP:无法使用curl 或file_get_contents 检索正确的ajax 响应

发布于 2024-12-20 04:58:03 字数 5174 浏览 1 评论 0原文

  1. 起始页
  2. 框架页面
  3. 结束页

我不知道我错过了什么。我尝试模仿 Firefox 请求标头,但它不起作用。

此外,框架页面使用 JavaScript ajax 请求到达结束页面。它将数据发布到$post_to_link(请参阅下面的代码),然后导航到预期结果(不是我的当前结果),其中包含大型上传链接位于。

预期输出:

/membersonly/components/com_iceplayer/GMorBMlet.php?url=http%3A%2F%2Fwww.megaupload.com%2F%3Fd%3DVNICBFWL&

当前输出:

  • file_get_contents输出3
  • curl输出错误403禁止访问

这是我的代码:

    // call it like so...
    echo GetHosterLink( 1148, 252636, '', '37fn8Oklq', 15, -75 );
    // $s is incremented every second you are 'visiting' the referer page
    // $m decreases below zero when you move your mouse `down` on the start page

    function GetHosterLink( $id, $link_id, $cap, $sec, $s, $m )
    {

        $link_page = str_replace( '[ID]', $id, 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?vid=[ID]' );
        $post = "id={$link_id}&s={$s}&iqs=&url=&m={$m}&cap=&sec={$sec}&t={$id}";

        $header = implode( "\r\n", array(
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
            "Accept-Encoding: gzip, deflate",
            "Accept-Language: en-us,en;q=0.5",
            "Cache-Control: no-cache",
            "Connection: keep-alive",
            "Content-Length: " . strlen( $post ),
            "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
            "Host: www.icefilms.info",
            "Pragma: no-cache",
            "Referer: http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?h=374&w=631&vid={$id}&img=",
            "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0"
        ));

        $opts = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => implode("\r\n",
                    array(
                        'Content-type: application/x-www-form-urlencoded',
                        'Content-length: ' . strlen( $post ),
                        'Referer: ' . $link_page . '&h=374&w=631',
                        'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0',
                        'Host: www.icefilms.info'
                    )
                ),
                'content' => http_build_query(
                    array(
                        'id' => $link_id,
                        's' => $s,
                        'sec' => $sec,
                        't' => $id,
                        'm' => $m,
                        'iqs' => '',
                        'url' => '',
                        'cap' => ''
                    )
                )
            )
        );

        $context  = stream_context_create($opts);

        $post_to_link = 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.phpAjaxResp.php';
        $get_result = file_get_contents( $post_to_link, false, $context );

        $f_result = cURL::DoRequest( $post_to_link, $post, '',
            array( array( CURLOPT_HTTPHEADER, $header ) ) );

        $f_r = array(
            'result' => $f_result,
            'get_result' => $get_result,
            'get_opts' => $opts,
            'get_response' => $http_response_header,
            'req_post' => $post,
            'req_href' => $post_to_link,
            'req_header' => $header
        );

        return ( $f_r );

    }

这是我的curl.php文件:

class cURL
{

    public static function DoRequest( $url, $post = '',
        $cookie_file = '', $variables = array() )
    {

        $curl = curl_init();
        @session_start();
        $cookie = ( 'PHPSESSID=' . session_id() . '; path=/' );
        @session_write_close();

        curl_setopt( $curl, CURLOPT_URL, $url );
        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

        if ( !empty( $cookie_file ) )
        {

            curl_setopt( $curl, CURLOPT_COOKIEFILE, $cookie_file );
            curl_setopt( $curl, CURLOPT_COOKIEJAR, $cookie_file );

        }

        if ( !empty( $post ) )
        {

            //curl_setopt( $curl, CURLOPT_POST, 1 );
            curl_setopt( $curl, CURLOPT_POSTFIELDS, $post );

        }

        foreach ( $variables as $var )
            curl_setopt( $curl, $var[0], $var[1] );

        $result = curl_exec( $curl );
        curl_close( $curl );

        return ( $result );

    }

}
  1. Start page
  2. Frame page
  3. End page

I can't figure out what I'm missing. I've tried mimicking the firefox request headers, but it doesn't work.

Also, the frame page reaches the end page using a javascript ajax request. It posts the data to $post_to_link (see code below) then navigates to the expected result (not my current result), where the megaupload link is located.

Expected output:

/membersonly/components/com_iceplayer/GMorBMlet.php?url=http%3A%2F%2Fwww.megaupload.com%2F%3Fd%3DVNICBFWL&

Current output:

  • file_get_contents outputs 3
  • curl outputs error 403 forbidden access

Here is my code:

    // call it like so...
    echo GetHosterLink( 1148, 252636, '', '37fn8Oklq', 15, -75 );
    // $s is incremented every second you are 'visiting' the referer page
    // $m decreases below zero when you move your mouse `down` on the start page

    function GetHosterLink( $id, $link_id, $cap, $sec, $s, $m )
    {

        $link_page = str_replace( '[ID]', $id, 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?vid=[ID]' );
        $post = "id={$link_id}&s={$s}&iqs=&url=&m={$m}&cap=&sec={$sec}&t={$id}";

        $header = implode( "\r\n", array(
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
            "Accept-Encoding: gzip, deflate",
            "Accept-Language: en-us,en;q=0.5",
            "Cache-Control: no-cache",
            "Connection: keep-alive",
            "Content-Length: " . strlen( $post ),
            "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
            "Host: www.icefilms.info",
            "Pragma: no-cache",
            "Referer: http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?h=374&w=631&vid={$id}&img=",
            "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0"
        ));

        $opts = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => implode("\r\n",
                    array(
                        'Content-type: application/x-www-form-urlencoded',
                        'Content-length: ' . strlen( $post ),
                        'Referer: ' . $link_page . '&h=374&w=631',
                        'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0',
                        'Host: www.icefilms.info'
                    )
                ),
                'content' => http_build_query(
                    array(
                        'id' => $link_id,
                        's' => $s,
                        'sec' => $sec,
                        't' => $id,
                        'm' => $m,
                        'iqs' => '',
                        'url' => '',
                        'cap' => ''
                    )
                )
            )
        );

        $context  = stream_context_create($opts);

        $post_to_link = 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.phpAjaxResp.php';
        $get_result = file_get_contents( $post_to_link, false, $context );

        $f_result = cURL::DoRequest( $post_to_link, $post, '',
            array( array( CURLOPT_HTTPHEADER, $header ) ) );

        $f_r = array(
            'result' => $f_result,
            'get_result' => $get_result,
            'get_opts' => $opts,
            'get_response' => $http_response_header,
            'req_post' => $post,
            'req_href' => $post_to_link,
            'req_header' => $header
        );

        return ( $f_r );

    }

Here is my curl.php file:

class cURL
{

    public static function DoRequest( $url, $post = '',
        $cookie_file = '', $variables = array() )
    {

        $curl = curl_init();
        @session_start();
        $cookie = ( 'PHPSESSID=' . session_id() . '; path=/' );
        @session_write_close();

        curl_setopt( $curl, CURLOPT_URL, $url );
        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

        if ( !empty( $cookie_file ) )
        {

            curl_setopt( $curl, CURLOPT_COOKIEFILE, $cookie_file );
            curl_setopt( $curl, CURLOPT_COOKIEJAR, $cookie_file );

        }

        if ( !empty( $post ) )
        {

            //curl_setopt( $curl, CURLOPT_POST, 1 );
            curl_setopt( $curl, CURLOPT_POSTFIELDS, $post );

        }

        foreach ( $variables as $var )
            curl_setopt( $curl, $var[0], $var[1] );

        $result = curl_exec( $curl );
        curl_close( $curl );

        return ( $result );

    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-12-27 04:58:03

尝试使用curl访问初始页面(您在$link_page中拥有的URL)并确保您指向的文件:

curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

存在并且可写。

然后使用相同的curl资源请求$post_to_link url。

通过访问初始页面,您将获得 cookie,并确保您的下一个请求有一个有效的会话。这也可以保护您在标头中提供的引用者。有很多方法可以计算“自动”请求,检查 cookie 以及您是否确实访问过“referer”链接之类的事情很常见。

Try visiting initial page (the one's url you have in $link_page) with curl and make sure the file you point to in:

curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

exists and is writeable.

Then request the $post_to_link url with same curl resource.

By visiting the initial page you are getting cookies and making sure there is a valid session for your next request. That also secures the referer you then provide in headers. There are many ways to figure "automatic" requests, and things like checking cookie and if you actually visited "referer"-ed link are quite common.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文