带curl的PHP表单
如果我的当前url与“”不同,我想在.php文件中显示一个简单的表单。所以首先我有一个卷发请求带curl的PHP表单,php,forms,curl,Php,Forms,Curl,如果我的当前url与“”不同,我想在.php文件中显示一个简单的表单。所以首先我有一个卷发请求 $ch = curl_init(); ... curl_setopt($ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($cookiePath)); curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($cookiePath)); curl_setopt($c
$ch = curl_init();
...
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($cookiePath));
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($cookiePath));
curl_setopt($ch, CURLOPT_URL, $urlLoginRedirect);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $commonHeaders);
$result = curl_exec($ch);
if ($result === FALSE) { die (curl_error($ch)); }
$actualUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$additionalHeaders = array(
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
'Referer: ' . $actualUrl,
'Upgrade-Insecure-Requests: 1'
);
$postData = 'email=email@example.com&password=my_password&_rememberMe=on&rememberMe=on&_eventId=submit&gCaptchaResponse=';
$headers = array_merge($commonHeaders, $additionalHeaders);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $actualUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
if ($result === FALSE) { die (curl_error($ch)); }
$actualUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
echo $actualUrl;
if($actualUrl !== 'https://www.example.com/')
{
// Show form and send post request with data
}
curl_close($ch);
?>
这就是问题所在。是否有一种方法可以在填充表单时不重新加载这个.php文件,如果没有,我是否应该再次调用curl_init()
//编辑
> I want to log into a website. First of all i send get request to get
> url and then post request to fill a form. Then from actual url i can
> check if i need to verify my account - if so, i get a special number
> to my email and i have to do another post request with this number but
> everything without closing an actual session. Can I send a reference
> of $ch to another file? Because if i send form data to self .php file
> connection will be closed (even if i do it with jquery/ajax i
> believe).
>
> Thanks.
有没有办法不重新加载
如果您使用JavaScript,这将是可能的。看看JQuery+AJAX的例子,这是一种简单的方法。我不确定您到底想实现什么-代码看起来像是模拟登录提交,但页面刷新与此无关。您可以使用javascript提交表单,并发出AJAX请求来调用php并获得结果