I am trying to use php curl to get the login token from an external webpage
but the login token I’m receiving is different from the actual one.
Could someone please tell me what I’m missing.
$ch = curl_init();
url_setopt($ch, CURLOPT_URL, "https://grprek.jeddahknowledgeschool.com/login/index.php");
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
echo $answer;
if (curl_error($ch)) {
echo curl_error($ch);
}
?>
<form action="<?php echo $virtualLink; ?>" method="post" target="_new" id="login" >
<input name="logintoken" type="hidden" value="<?php echo $vlLoginToken;?>" />
<input style="background-color: transparent;" id="username" name="username" type="hidden" value="<?php echo $username;?>" >
<input id="password" name="password" type="hidden" value="<?php echo $vlPassword;?>">
<input style=" width:100px; height:100px; margin-right:auto; margin-left:auto; display:block; border:none; background-color: transparent;"
src=""
type="image"
alt="turnitin"
title="turnitin">
</form>
</td>
2
Answers
Using a fairly basic and re-usable function below to make the curl requests you would initially perform a
GET
request to begin the session. The initialGET
request is used to discover and store the cookies used and to parse the HTML to find thelogintoken
from the form.You use
DOMDocument/DOMXpath
to process the HTML and find the token. That discovered token will then be used to create thePOST
request – ie: the login.what does that even mean? what is
the actual one
?Anyhow, what you’re missing is the cookie session. the loginToken is tied directly to the cookie session, and without the cookie session, the loginToken is useless. You need to capture both the cookie session id and login token:
prints: