有可能登录到一个网站,然后用PHP从该用户的网站上读取信息吗


Is it possible to log into a site then read information off the site under that user - in PHP?

问题:有没有可能登录到一个网站,然后从该用户(PHP(的网站上读取信息?

示例:许多网站都是动态的,并且有php从数据库中提取信息。比方说example.com有登录名。

登录页面时example.com/test.php显示:"你好用户",未登录时显示:"您不是用户,请在此处登录">

假设身份验证过程是通过会话进行的,用户将通过发布一个带有标签"user"answers"pass"的表单登录,如果正确,将启动一个会话,允许用户在example.com/test.php 上看到消息

问题:有可能登录到一个网站,然后在该用户的领导下从网站上读取信息吗?

我一直在四处寻找,不知道该如何处理。任何事情都会有帮助。提前谢谢。

当然,您可以使用file_get_contents+streams和/或curl在PHP中获取数据。有一些库允许您在php中执行javascript,因此即使是动态页面也可以处理。

问题是,无论你想做什么,基本上都值得在PHP中构建浏览器。

您可以(使用curl(

        $ckfile = tempnam ("/tmp", "CURLCOOKIE");
        $ch = curl_init("http://example.com/index.php");
        curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec ($ch);
        curl_close($ch);

        $ch = curl_init();
        $fields = array(
                'username' => 'genesis',
                'pass' => 'pass',
                'other' => 'post fields'
        );
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        curl_setopt($ch, CURLOPT_URL, "http://example.com/login.php");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $result = curl_exec($ch);
        curl_close($ch);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://example.com/logged_page.php");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $needed_information = curl_exec($ch);
        curl_close($ch);

PHP可以做到这一点,但不是为这个目的而设计的。

PHP语法基于Perl,这可能更适合。您也可以尝试Python。

如果域A,B,其中A!=B、 那么你就不能这么做了,因为同源政策(很容易(。您可以登录SSO。有一些库可用,我还没有尝试过,例如=>http://www.jasny.net/articles/simple-single-sign-on-for-php/