Home  >  Article  >  Backend Development  >  程序员 - PHP如何模拟POST提交登录?

程序员 - PHP如何模拟POST提交登录?

WBOY
WBOYOriginal
2016-06-06 20:46:441169browse

腾讯 PHP 面试题:

如果PHP网站的表单用户名字段是username,密码是password 没有验证码,cookie的键是username,你如何模拟登录,就是不去登录页面,也能实现登录,假设账户“张三”密码123 是该网站的正确密码

求详细代码

回复内容:

腾讯 PHP 面试题:

如果PHP网站的表单用户名字段是username,密码是password 没有验证码,cookie的键是username,你如何模拟登录,就是不去登录页面,也能实现登录,假设账户“张三”密码123 是该网站的正确密码

求详细代码

<code>$url = ''; //POST地址
$password = ''; //密码

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'username='.$_COOKIE['username'].'&password='.$password);
/**
 * 如果$url是https则需要取消下面两行注释
 * curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 * curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
 */
curl_exec($curl);
curl_close($curl);
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn