【问题标题】:How do I make php really work with an https site?如何使 php 真正与 https 站点一起工作?
【发布时间】:2017-06-10 11:05:42
【问题描述】:

这个问题类似于this older question

那里的解决方案似乎对我有用,但我得到的结果是未登录。我在第二个请求中得到了页面,但不是作为用户。 我应该改变什么? 代码如下:

<?php
$urlini='https://www.example.com/login';
$url='https://www.example.com/page-12345';

$ch = curl_init();
$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_URL, $urlini);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/certificate.pem");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('email' => 'email@example.com' , 'password' => 'password')));
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$store = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

当我没有回显$response,回显$store 时,我看到表单中填写了用户名,但没有填写密码。网站上登录表单的代码是:

<div class="form_wrapper"><div class="form" id="login_form">
<span class="form_title hidden-xs">Log in</span><input id="email" name="id" type="email" placeholder="Email address" class="validate[required,custom[email]]"/>
<input id="password" name="password" type="password" placeholder="Password" class="validate[required,minSize[5],custom[passwordLegalChars]]"/><a
id="login_button" class="css_button css_button_big css_button_default" role="button" tabindex="0" >Log in</a>

【问题讨论】:

  • cURL Login to HTTPS site的可能重复
  • @bub:我说问题很相似,我在那里尝试了解决方案,但它并没有为我解决问题。这里的问题与其他问题不重复,因为其他问题的答案是我的出发点。
  • 也许您缺少一些用于登录的帖子字段,或者另一个常见问题是缺少发送用户代理字符串。很难说没有看到输出,登录页面的来源知道是否缺少任何东西。

标签: php ssl curl cookies


【解决方案1】:

我已经设法解决了这个问题。 事实证明,登录页面确实首先将登录信息发送到了某个 bot 预防站点。使用 developer->inspector->network 和启用持久日志给了我真正的登录 url。相应地更改$urlini 后,代码工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 2020-10-24
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    相关资源
    最近更新 更多