我有两个站点A和B我希望能够从站点A有一个经过验证的用户登录到站点B,
网站A - 使用php;
站点B - 使用Zend Framework。
我想在网站A上有一个iframe到网站B的私有部分或重定向到网站B. 当我从网站A上的表单做一个html帖子时,凭据我被重定向并登录一切正常,我想在php中从服务器端更安全地做。当我发布使用php curl时,用户没有登录iframe,我累了重定向,但用户还没有登录到站点B.
我不知道为什么html表单有效且php curl没有?我想用curl发送其他东西,或者是Zend有问题吗?
-----好了一些谷歌搜索后我把问题缩小到饼干我相信我必须设置它们但我不知道如何?它是否正确?我将如何在PHP中设置它们?或者我传递cookie设置到浏览器的标题并转发到站点B?如果是这样我该怎么做?
这是我目前的代码。
<?php
$data = array(
'useremail' => 'someemail',
'password' => 'somepassword'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://siteb.com/account/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Cookie management.
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>
<html>
<body>
<iframe src="http://SiteB.com/account/login" width="950" height="700"></iframe>
<form action="http://SiteB.com/account/login" method="post">
email: <input type="text" name="useremail" value="useremail" /><br />
password: <input type="text" name="password" value="somepassword" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
感谢您的时间和帮助。
答案 0 :(得分:2)
“当我使用php curl发布时,用户没有在iframe中登录,我累了重定向但是用户还没有登录到站点B上。”
我的回答:把Php-Curl想象成一个broswer。并且您正在以不同的浏览器执行脚本。要使iframe身份验证起作用,需要在浏览器中设置cookie。从PHP脚本进行身份验证时,cookie将在PHP-curl broswer上设置。这两个broswers都不共享cookie。我不认为你可以让用户像这样登录。
您使用的是Windows服务器还是Linux服务器?
我相信我必须设置它们,但我不知道如何?它是否正确? 您正在通过使用curl选项来使用cookie来做到这一点。
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); // Cookie management.
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
顺便说一句,您能否尝试以下代码并检查Cookie文件夹中是否生成了Cookie%randNum%.txt?顺便说一句,在执行之前,在与脚本相同的文件夹中创建一个cookie文件夹。只是为了确保你在文件夹中存放所有cookie而不是在脚本文件中传播。
<?
$mypath = getcwd();
$mypath = preg_replace('/\\\\/', '/', $mypath);
$rand = rand(1, 15000);
$cookie_file_path = "$mypath/cookies/cookie$rand.txt";
$data = array(
'useremail' => 'someemail',
'password' => 'somepassword'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://siteb.com/account/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); // Cookie management.
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>
答案 1 :(得分:0)