Hallo, wie oben beschrieben geht es um cURL mit PHP.
curl.php
URL ist wegen Copyright nicht genannt.
Das Problem ist, dass keine Cookie-Datei entsteht, und ich nicht auf die Seite mit dem Content to grab weitergeleitet werde.
Aufbau der Seite:
index.php hat das login form:
wenn man auf login.php geht, landet man auf index.php mit dem oben genannten formular.
Folgendes wird beim network capturing mit den Dev-Tools analysiert:
Host: example.de
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Origin: https://example.de
Connection: keep-alive
Referer: https://example.de/index.php
Cookie: PHPSESSID=0icgno4b8qisgdclpn3mfgc1vn
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
--
username=email@email.de&password=test123
Danke
Gruß Fynn
curl.php
PHP-Code:
<?php
//username and password of account
$username = trim($values["email@email.de"]);
$password = trim($values["test123"]);
//set the directory for the cookie using defined document root var
$path = DOC_ROOT."/ctemp";
//build a unique path with every request to store. the info per user with custom func. I used this function to build unique paths based on member ID, that was for my use case. It can be a regular dir.
//$path = build_unique_path($path); // this was for my use case
//login form action url
$url="https://www.example.com/login/action";
$postinfo = "email=".$username."&password=".$password;
$cookie_file_path = $path."/cookie.txt";
$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, "http://www.example.com/page/");
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
?>
Das Problem ist, dass keine Cookie-Datei entsteht, und ich nicht auf die Seite mit dem Content to grab weitergeleitet werde.
Aufbau der Seite:
index.php hat das login form:
HTML-Code:
<form id="login_form" action="example.de/login.php" method="post" > <div class="form-group"> <input id="username" type="text" name="username" class="form-control" placeholder="Benutzername"/> </div> <div class="form-group"> <input id="password" type="password" name="password" class="form-control" placeholder="Passwort"/> </div> <button type="submit" class="btn btn-primary btn-block">Login</button>
Folgendes wird beim network capturing mit den Dev-Tools analysiert:
Host: example.de
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Origin: https://example.de
Connection: keep-alive
Referer: https://example.de/index.php
Cookie: PHPSESSID=0icgno4b8qisgdclpn3mfgc1vn
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
--
username=email@email.de&password=test123
Danke
Gruß Fynn
Kommentar