cURL Логин не работает на www.profi-ortung.de/index.php - PullRequest
0 голосов
/ 27 мая 2020

Я не могу получить логин с помощью cURL. Я все еще PHP новичок и не могу выполнить эту работу. Файл Cook ie .txt создается, но с параметром false. Правильно ли написан сценарий? спасибо.

Это страница с формой: https://www.profi-ortung.de/index.php

<?php

if($_GET){
    foreach ($_POST as $key => $value) 
        echo htmlspecialchars($key)." = ".htmlspecialchars($value)."\n";
} 
// Controll the Post Fields of target, to be sure if there is hidden values. ( just open the form of the site with ctrl+shift+c and change action="localhost/curl.php" to here )

function get_curl($name, $pass, $loginForm, $page){

    $USER_AGENT = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36'; //browser defination
    $COOKIE_FILE = 'cookie.txt'; // create a txt file called cookie.txt
    $LOGIN_FORM_URL = $loginForm; //  login form 
    $LOGIN_ACTION_URL = $loginForm; // where login form goes (action=""), if its same, just write $loginForm
    $postValues = array(
        'username' => $name,
        'password' => $pass
    );
    $curl = curl_init(); // curl start
    curl_setopt($curl, CURLOPT_URL, $LOGIN_ACTION_URL); // url define
    curl_setopt($curl, CURLOPT_POST, true); // form method = post
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postValues)); //// our postfields values.
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // no SSL problem 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // no SSL problem
    curl_setopt($curl, CURLOPT_COOKIEJAR, $COOKIE_FILE); // cookie file to write our Session Infos
    curl_setopt($curl, CURLOPT_USERAGENT, $USER_AGENT); // wo am i?
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //// give me the result when curl done.
    curl_setopt($curl, CURLOPT_REFERER, $LOGIN_FORM_URL); // where we are coming ?
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); // should we follow the link, after curl done
    curl_exec($curl); //execute curl

    if(curl_errno($curl)){
        throw new Exception(curl_error($curl)); // if there is an error, show me
    }

    curl_setopt($curl, CURLOPT_URL, $page); // which page do you wanna get after login
    curl_setopt($curl, CURLOPT_COOKIEJAR, $COOKIE_FILE); // our Session File
    curl_setopt($curl, CURLOPT_USERAGENT, $USER_AGENT); //who we are
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // no SSL problem 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // no SSL problem 
    $get = curl_exec($curl);

    switch ($http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) { // success ?
    case 200:
        return  $get;//  give me the all content
        break;
    default:
      return "error";
    }
    curl_close($curl); //curl done
}

$username = "xxx@xxx.xx"; // your username
$password = "xxx"; // your password
$formPage = "https://www.profi-ortung.de/login.php"; // login form page 
$indexseite = "https://www.profi-ortung.de/home.php#/home"; //after login which page do we wanna go 
$get = get_curl($username, $password, $formPage, $indexseite);

    //preg_match('@<title>(.*?)</title>@si', $get, $title); //title
    //echo strtoupper($title[1]) . $eol;
echo $get;

?>

Это заголовок ответа, заголовок запроса и данные формы:

 https://www.profi-ortung.de/login.php
Request Method: POST
Status Code: 302 Found
Remote Address: 217.199.194.85:443
Referrer Policy: no-referrer-when-downgrade
Cache-Control: no-store, no-cache, must-revalidate
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Date: Wed, 27 May 2020 13:43:28 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Location: https://www.profi-ortung.de/home.php
Pragma: no-cache
Server: nginx/1.14.0 (Ubuntu)
Transfer-Encoding: chunked
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 49
Content-Type: application/x-www-form-urlencoded
Cookie: PHPSESSID=ld9u08hf79gho7i5igm8p3o2oo; _ga=GA1.2.697977144.1590580332; _gid=GA1.2.1112462273.1590580332; userSettings=%7B%22group_list%22%3Afalse%2C%22list_name%22%3A%22standart%22%2C%22sort_type%22%3A%22name%22%2C%22display_device_count%22%3A14%2C%22language%22%3A%22de%22%2C%22timezone%22%3A%22Europe%2FBerlin%22%2C%22auto_reload%22%3Afalse%2C%22filter_zero_trips%22%3Afalse%2C%22customerInformation%22%3Afalse%2C%22demoInformationHome%22%3Afalse%2C%22demoInformationRotes%22%3Afalse%2C%22demoInformationReports%22%3Afalse%2C%22demoRouteInfo%22%3Afalse%2C%22demoLocationInfo%22%3Afalse%2C%22demoLiveInfo%22%3Afalse%2C%22demoDailyInfo%22%3Afalse%2C%22demoSpeedInfo%22%3Afalse%2C%22demoInformationInouts%22%3Afalse%2C%22demoInformationRouteTracking%22%3Afalse%2C%22rightSideBar%22%3Afalse%7D; __tawkuuid=e::profi-ortung.de::dTn3TpHKIfOpM8iyJgPbS7eTuhk1dqmhZ0agsZM7S1HOfwmHva5Gx9juqBcZ2UYo::2; TawkConnectionTime=0
Host: www.profi-ortung.de
Origin: https://www.profi-ortung.de
Pragma: no-cache
Referer: https://www.profi-ortung.de/index.php
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36
username: xxx@xxx.xx
password: xxx
...