【发布时间】:2023-03-22 22:50:01
【问题描述】:
这是我在 2015 年初做的一个类的函数代码的一部分。今天它不再工作了。我的代码中定义的变量,所以这不是问题......
既然我们已经清楚了,让我们进入正题:
问题:
- 不生成 cookie
- 在登录页面中,我得到一个带有“ 安全政策” ...
- 我被重定向到 https://facebook.com/common/invalid_request.php 当我登录时( 下面我会像记录日志一样解释)
糟糕的解决方案:
- 要生成 cookie,您所做的只是使用 Chrome 的扩展程序向您显示 cookies.txt,称为 Netscape 格式的 cookies,然后使用 facebook 复制该文件并登录,因为我不允许使用没有 Log 的 cookie 登录。
-
我无法修复它
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/'); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->CONFIG['cookie']); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $this->CONFIG['useragent']); curl_setopt($ch, CURLOPT_REFERER, 'http://www.facebook.com'); curl_exec($ch) or die(curl_error($ch)); curl_close($ch); unset($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.php'); curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($email).'&pass='.urlencode($pass).'&login=Login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->CONFIG['cookie']); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->CONFIG['cookie']); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $this->CONFIG['useragent']); curl_setopt($ch, CURLOPT_REFERER, 'http://www.facebook.com'); $page = curl_exec($ch) or die(curl_error($ch)); file_put_contents(getcwd().'/debug.html', $page); preg_match('/<body class="([^<]+)" dir="ltr">/', $page, $web); if(file_exists($this->CONFIG['token'])) unlink($this->CONFIG['token']); if(preg_match('/home/i', $web[1])) { $this->login = true; return true; } else { return false; } curl_close($ch);
【问题讨论】:
-
我修正了您的英语和问题的格式,以帮助您获得答案。您问题中两个编号列表中的第一项 (1.) 令人困惑。如果可能,请修改它们以使其更清晰。
-
编辑器有StackOverflow,我不喜欢不惜一切代价......所以我用以为这有多糟糕。