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

时间:2022-10-08 18:12:50
  1. Script output. (broken)
  2. 脚本的输出。(破碎)
  3. Start page
  4. 开始页面
  5. Frame page
  6. 框架页面
  7. End page
  8. 结束页

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.

我不知道我错过了什么。我尝试过模仿firefox的请求头,但是它不起作用。此外,框架页面通过javascript ajax请求到达结束页面。它将数据发布到$post_to_link(请参阅下面的代码),然后导航到预期结果(不是我当前的结果),megaupload链接位于那里。

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

预期的输出:/ membersonly /组件/ com_iceplayer / GMorBMlet.php ? url = fwww.megaupload.com http % 3 % 2 f % 2 % 2 f % 3 fd dvnicbfwl& % 3

Current output:

电流输出:

  • file_get_contents outputs 3
  • 函数输出3
  • curl outputs error 403 forbidden access
  • curl输出错误403禁止访问

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:

这是我的卷发。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 个解决方案

#1


3  

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访问初始页面($link_page中的url)并确保指向的文件:

curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

exists and is writeable.

存在并且是可写的。

Then request the $post_to_link url with same curl resource.

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

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.

通过访问初始页面,您将获得cookie,并确保下一个请求有一个有效会话。这也保护了您在header中提供的引用程序。有很多方法可以计算“自动”请求,像检查cookie,如果你真的访问了“referer”-ed链接,这些都是很常见的。

#1


3  

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访问初始页面($link_page中的url)并确保指向的文件:

curl_setopt( $curl, CURLOPT_COOKIE, $cookie );

exists and is writeable.

存在并且是可写的。

Then request the $post_to_link url with same curl resource.

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

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.

通过访问初始页面,您将获得cookie,并确保下一个请求有一个有效会话。这也保护了您在header中提供的引用程序。有很多方法可以计算“自动”请求,像检查cookie,如果你真的访问了“referer”-ed链接,这些都是很常见的。