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 61 62
|
// Récupération du token
$url = $url_log;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
// Pour éviter les Warnings : htmlParseStartTag: misplaced <head> tag in Entity
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($response);
$token = $doc->getElementById("signin__csrf_token")->attributes->getNamedItem("value")->value;
echo $token;
$data = "signin[username]=$username&signin[password]=$password&signin[_csrf_token]=$token";
//$data = "signin[username]=$username&signin[password]=$password";
// LOGING + Récupération de la page souhaitée.
//login form action url
$url=$url_log;
//$postinfo = "email=".$username."&password=".$password;
$postinfo = $data;
$cookie_file_path = $path;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, $url_wanted);
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
echo $html; |
Partager