Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从其他网页登录网站_Php_Post_Curl_Login_Get - Fatal编程技术网

使用PHP从其他网页登录网站

使用PHP从其他网页登录网站,php,post,curl,login,get,Php,Post,Curl,Login,Get,所以我有一个网站 还有一个我想登录的网站; 我想要一个脚本,可以填写从我的网站登录表单(用户名和密码) 所以当用户点击 他应该直接登录并发送到欢迎页面 我得到了这个密码 $url = "http://target.com"; $post = "username=John&password=12345&login=++Ba%F0lan++"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); cu

所以我有一个网站 还有一个我想登录的网站; 我想要一个脚本,可以填写从我的网站登录表单(用户名和密码)

所以当用户点击

他应该直接登录并发送到欢迎页面

我得到了这个密码

$url = "http://target.com";
$post = "username=John&password=12345&login=++Ba%F0lan++";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
curl_close($ch);
但它并没有把我转到欢迎页面。相反,它显示了(未找到页面)上的错误

它也不会从url获取用户名和密码数据。但我想我以后会自己解决的


有什么帮助吗?

好的。。。如果
target.com
不明确支持某种类型的代理登录,这基本上比您想象的要困难得多。这里有三个派对:

client   ---->   example.com   ---->   target.com
通常,客户端登录到
target.com
,然后收到一个会话cookie,这是他的登录令牌。只有
target.com
可以为
target.com
设置cookie

当您代理此过程并让
example.com
登录到
target.com
时,
example.com
接收cookie。没关系,现在
example.com
已通过身份验证。但它无法将此身份验证传递给客户端,因为
example.com
无法代表
target.com
设置cookie
example.com
可以将收到的cookie传递给客户端,但该cookie仅对
example.com
有效


除非
target.com
支持某种不依赖cookies的基于URL的登录方案,否则你就完蛋了。

对我来说,这看起来像是钓鱼脚本。@Peter(他的评论曾经在这里)当然,因此,
example.com
只需准备带有预填充值的登录表单,就可以让客户端通过Javascript自动提交。这是可行的,但如果
target.com
采用合理的CSRF保护,也可能失败。