1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <?php
define('LOGIN', 'test');
define('PASSWORD', 'test');
define('AUTHENTIFICATION', 'http://demo.living-bots.net/index.php?s=logincheck');
define('PAGE_PRIVEE', 'http://demo.living-bots.net/index.php?s=ghost&botid=10048');
define('PAGE_TEST', 'http://demo.living-bots.net/index.php?s=ghoststatus');
$sid = '';
/**
* Première connexion : authentification
**/
$ch = curl_init(AUTHENTIFICATION);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'name' => LOGIN,
'pass' => PASSWORD
)
);
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('cookie.txt'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$ret = curl_exec($ch);
if ($ret === FALSE) {
die(curl_error());
}
curl_close($ch);
if (preg_match('/(PHPSESSID=[0-9a-z,-]{32,40})/i', $ret, $m)) {
$sid = '?' . $m[1];
} else if (preg_match('#<input\s+type="hidden"\s+name="([^\r\n\t <>\'"\\\]+)"\s+value="([0-9a-z,-]{32,40})"\s*/?>#i', $ret, $m)) {
$sid = '?' . $m[1] . '=' . $m[2];
}
/**
* Deuxième partie : réutilisation de la session sur une page tierce
**/
$ch = curl_init(PAGE_PRIVEE . $sid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
$ret = curl_exec($ch);
if ($ret === FALSE) {
die(curl_error());
}
curl_close($ch);
echo $ret;
$ch = curl_init(PAGE_TEST . $sid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
$ret = curl_exec($ch);
if ($ret === FALSE) {
die(curl_error());
}
curl_close($ch);
echo $ret;
?> |
Partager