当前位置:Gxlcms > PHP教程 > 程序员-PHP如何模拟POST提交登录?

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

时间:2021-07-01 10:21:17 帮助过:17人阅读

腾讯 PHP 面试题:

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

求详细代码

回复内容:

腾讯 PHP 面试题:

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

求详细代码

$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);

人气教程排行