I would like to show a simple form in .php file if my current url is different than "https://www.example.com/". So first of all i have a cURL request
$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);
?>
And here is the question. Is there a way to not reload this .php file when form is filled, and if not - should I call curl_init() again or not?
// EDIT
> 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.
Is there a way to not reload
It's will be posible if you will use JavaScript. Look for examples JQuery+AJAX, it's a simple way.