I am using file_get_contents function to get the login token of a page to put it in my form and submit the username and password along with the login token to achieve auto-login from my site to another site.
I'm loading the correct page I need, the username and password are correct, but the login token I'm receiving when I use file_get_contents is different from the login token on the actual page and if I copy the login token from the site and paste it in my form. The auto login is working great, but I'm not sure why the login token I am getting with file_get_contents is incorrect.
<td><?php
$txt1 = file_get_contents($virtualLink, FALSE );
preg_match('/\<input\stype="hidden".*name="logintoken".*value="(.*)".*>/', $txt1, $matchesT3);
if (count($matchesT3) >1) {
$vlLoginToken = $matchesT3[1];
}
?>
<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 $mailUsername;?>" >
<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="" title=""></form>
</td>
EDIT 1: I used this to get session cookie:
file_get_contents($virtualLink);
$cookies = array();
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
And I got this: Array ( [MoodleSession] => 9a3320b638bff0622dd834951fc8f348 ) How Can I create a stream with this?