Created
October 15, 2014 16:59
-
-
Save tjoskar/1d7806ab145d052872d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$username = ''; | |
$password = ''; | |
$points = ''; | |
$login_url = 'https://www3.student.liu.se/portal/login'; | |
$redirect = 1; | |
$redirect_url = '/portal/sv/portal/'; | |
$time = 0; | |
$login_para = ''; | |
// Lets do this | |
$dom = new DOMDocument('1.0'); | |
@$dom->loadHTMLFile($login_url); | |
// Get all inputs | |
$nodes = $dom->getElementsByTagName('input'); | |
// Loop through elements | |
foreach ($nodes as $node) { | |
if ($node->hasAttributes()) { | |
foreach ($node->attributes as $attribute) { | |
if ($attribute->nodeName == 'name' && $attribute->nodeValue == 'login_para') { | |
$login_para = $dom->saveHTML($node); | |
} elseif ($attribute->nodeName == 'name' && $attribute->nodeValue == 'time') { | |
$time = $dom->saveHTML($node); | |
} | |
} | |
} | |
} unset($node); | |
// Parse html as xml | |
// First the time (maybe we can use local time?) | |
$time = str_replace(">", " />", $time); | |
$x = (array) new SimpleXMLElement($time); | |
$time = $x['@attributes']['value']; | |
// And then the login_para | |
$login_para = str_replace(">", " />", $login_para); | |
$x = (array) new SimpleXMLElement($login_para); | |
$login_para = $x['@attributes']['value']; | |
$post_data = 'user='.$username. | |
'&pass='.$password. | |
'&time='.$time. | |
'&login_para='.$login_para. | |
'&redirect='.$redirect. | |
'&redirect_url='.$redirect_url; | |
// Init curl | |
$ch = curl_init(); | |
// Set the URL to work with | |
curl_setopt($ch, CURLOPT_URL, $login_url); | |
// Enable HTTP POST | |
curl_setopt($ch, CURLOPT_POST, 1); | |
// Set the post parameters | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); | |
// Handle cookies for the login | |
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); | |
// Be quiet | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// Execute the request (the login) | |
$store = curl_exec($ch); | |
// The login is now done | |
// Get the result page | |
curl_setopt($ch, CURLOPT_URL, 'https://www3.student.liu.se/portal/studieresultat/'); | |
// Execute the request | |
$content = curl_exec($ch); | |
// Has the number of points ben updated? | |
if (strpos(utf8_encode($content), $points) !== false) { | |
echo 'Du har inte fått in något resultat'."\n"; | |
} else { | |
echo 'Du har ett resultat'."\n"; | |
} | |
// close cURL resource, and free up system resources | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment