我正在尝试创建一个功能,允许用户点击一个按钮,该按钮将通过登录详细信息发送到外部网站,然后在登录iframe后显示页面。任何人都知道最好的方法,我目前有这个代码,因为我读cURL函数有效,但我不知道如何让这个带回iframe或如何链接按钮来调用函数,我是PHP新手,所以任何帮助都将不胜感激!
<?php
$username="user";
$password="pass";
$initials="ABC";
$cookie="cookie.txt";
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$post = array(
'userId' =>$username,
'password' =>$password,
'initials' =>$initials
);
$post_data = http_build_query($post);
$ch = curl_init('https://www.example.com');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);// This stores the cookie , you can use it later if you have to make more request which requires user to be loged in
curl_exec($ch);
curl_close($ch);
?>
答案 0 :(得分:0)
你可以在登录页面上发帖子来记录服务器。但我猜你真的希望当前用户登录网站?由于Curl请求是从服务器而不是从用户完成的,因此无法正常工作。
如果您还控制其他网站,您可以通过CURL将此类哈希代码发送到此站点,将其保存在本地数据库中,并向用户发送包含哈希码的链接。在另一台服务器上,您可以将此哈希代码与数据库中的哈希代码匹配,如果匹配,请将用户登录。