Bonjour,
Un de mes sites vient de passer en privé, donc je dois me connecter pour pouvoir accéder a des listes que je récupérais avant qu’il ne passe en privé.
Je vous avouerai que c’est la première fois en plusieurs années que j’ai ce cas de figure.
Tout mon code est en PHP, mais depuis que je dois me connecter, plus rien ne fonctionne, forcément
Alors j’ai réussi à me connecter via cURL et un cookie que j’ai ajouté depuis Firefox, mais le cookie casse au bout d’une heure, donc cette méthode n’est pas viable.
Il y a aussi le cookie cURL de PHP, j’arrive à me connecter et garder un cookie dans un fichier texte, mais ça ne fonctionne pas, lorsque je renvoie ma page, je ne suis pas connecté.
Par contre, comme dit plus haut, si je prends la valeur du cookie de Firefox, je le met dans le fichier cookie.txt, là je suis bien connecté. (mais cette méthode n’est pas viable)
Ensuite, je suis sur mutualisé, donc je ne peux pas utiliser de logiciel comme Puppeteer ou Selenium.
Voici mon script PHP : (je ne peux pas donner le site en raison des reègles du forum)
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/cfg/config.php';
function curl_debug($ch) {
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $verbose);
return $verbose;
}
$ch = curl_init();
$post_fields = [
'id' => 'login',
'pass' => 'mdp'
];
curl_setopt($ch, CURLOPT_URL, 'https://www.site.io/auth/login');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/home/www/projets/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/home/www/projets/cookies.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language: fr-FR',
'Referer: https://www.site.io/auth/login',
'DNT: 1',
'Sec-GPC: 1',
'Connection: keep-alive',
'Upgrade-Insecure-Requests: 1',
'Sec-Fetch-Dest: document',
'Sec-Fetch-Mode: navigate',
'Sec-Fetch-Site: same-origin',
'Sec-Fetch-User: ?1',
'Priority: u=1',
'Pragma: no-cache',
'Cache-Control: no-cache',
]);
$verbose = curl_debug($ch);
$response = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Erreur de connexion : '.curl_error($ch);
} else {
echo 'Connexion réussie.';
// Afficher le débogage
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "cURL verbose log:\n", p(htmlspecialchars($verboseLog)), "\n";
}
curl_setopt($ch, CURLOPT_URL, 'https://www.site.io/torrents/exclus');
curl_setopt($ch, CURLOPT_POST, false);
$response_protected = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Erreur d’accès à la page protégée : '.curl_error($ch);
} else {
echo 'Accès à la page protégée réussi.';
echo 'Contenu de la page : '.$response_protected;
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "cURL verbose log:\n", p(htmlspecialchars($verboseLog)), "\n";
}
curl_close($ch);
Là, c’est le code pour afficher le log de connexion avec cURL.
Voici le log de cURL :
cURL verbose log:
* Trying 2606:4700:3033::6815:404c...
* TCP_NODELAY set
* Connected to www.site.io (2606:4700:3033::6815:404c) port 443 (#0)
* found 431 certificates in /etc/ssl/certs
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_CHACHA20_POLY1305
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: site.io (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: CN=site.io
* start date: Fri, 17 May 2024 02:28:52 GMT
* expire date: Thu, 15 Aug 2024 02:28:51 GMT
* issuer: C=US,O=Google Trust Services LLC,CN=GTS CA 1P5
* compression: NULL
* ALPN, server accepted to use h2
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5570536e07b0)
> POST /auth/login HTTP/2
Host: www.site.io
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: fr-FR
Referer: https://www.site.io/auth/login
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=1
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 41
Content-Type: application/x-www-form-urlencoded
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* We are completely uploaded and fine
< HTTP/2 200
< date: Sun, 19 May 2024 15:29:43 GMT
< content-type: text/html; charset=UTF-8
* Added cookie chips_="4ae68htjrqdrclqnj12jfpcvi961pp01" for domain site.io, path /, expire 1716139783
< set-cookie: chips_=4ae68htjrqdrclqnj12jfpcvi961pp01; expires=Sun, 19-May-2024 17:29:43 GMT; Max-Age=7200; path=/; SameSite=None; domain=.site.io; secure; HttpOnly
< expires: Thu, 19 Nov 1981 08:52:00 GMT
< cache-control: no-store, no-cache, must-revalidate
< pragma: no-cache
< x-frame-options: SAMEORIGIN
< x-content-type-options: nosniff
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=xFjfgm0JrZG5xlct6R4YPNuYj8EJBofHdeo%2FdDbA7UdbG8qiQ0uG8WdRgduf13RDYr2dcxrbvIAgGacHR%2BLV0gQYa%2FwaMphwtIIsCISZk534ITWP4%2Bsx8CCWiFDOsopbW3v3bQLlPYwt"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: 88651fc4adde9ef4-CDG
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host www.site.io left intact
* Found bundle for host www.site.io: 0x5570536244b0 [can multiplex]
* Re-using existing connection! (#0) with host www.site.io
* Connected to www.site.io (2606:4700:3033::6815:404c) port 443 (#0)
* Using Stream ID: 3 (easy handle 0x5570536e07b0)
> GET /torrents/exclus HTTP/2
Host: www.site.io
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Cookie: chips_=4ae68htjrqdrclqnj12jfpcvi961pp01
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: fr-FR
Referer: https://www.site.io/auth/login
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=1
Pragma: no-cache
Cache-Control: no-cache
< HTTP/2 307
< date: Sun, 19 May 2024 15:29:43 GMT
< content-type: text/html; charset=UTF-8
< location: https://www.site.io/auth/login
< expires: Thu, 19 Nov 1981 08:52:00 GMT
< cache-control: no-store, no-cache, must-revalidate
< pragma: no-cache
< x-frame-options: SAMEORIGIN
< x-content-type-options: nosniff
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=Zzn%2BezkhJcL6fW3pd13m5mmB%2F5Luhbs1xTpcowI2LqaQFkuZXdC2UdKwVJcggsu%2BafY%2FqRyk40pBbQAyiLixwoaCG3VhHEB8OMJX4EJp%2BRvBau6RrmGe90QO2PKARuFpkxeHZGotKWc2"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: 88651fc4de079ef4-CDG
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host www.site.io left intact
* Issue another request to this URL: 'https://www.site.io/auth/login'
* Found bundle for host www.site.io: 0x5570536244b0 [can multiplex]
* Re-using existing connection! (#0) with host www.site.io
* Connected to www.site.io (2606:4700:3033::6815:404c) port 443 (#0)
* Using Stream ID: 5 (easy handle 0x5570536e07b0)
> GET /auth/login HTTP/2
Host: www.site.io
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Cookie: chips_=4ae68htjrqdrclqnj12jfpcvi961pp01
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: fr-FR
Referer: https://www.site.io/auth/login
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=1
Pragma: no-cache
Cache-Control: no-cache
< HTTP/2 200
< date: Sun, 19 May 2024 15:29:43 GMT
< content-type: text/html; charset=UTF-8
< expires: Thu, 19 Nov 1981 08:52:00 GMT
< cache-control: no-store, no-cache, must-revalidate
< pragma: no-cache
< x-frame-options: SAMEORIGIN
< x-content-type-options: nosniff
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=D2fDiMPFczM7PwyY52v6isFSN4C8c%2BgoceSm59CRAVXCYQXb51jlnbCX5Ocr20kuB3jf2%2B%2FAbGQRVXr6f4yQEGyXX70Jql6QFFJVEUQafZEtPM9HQLFiYy6rVofQgfa73A"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: 88651fc50e299ef4-CDG
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host www.site.io left intact
Alors je n’ai pas d’erreur, juste que la variable qui devrai afficher la dernière page où je suis connecté, elle m’affiche seulement le formulaire de connexion.
Voilà, si quelqu’un peut me renseigner sur comment faire ?
Ah et j’oubliais, il n’y a pas de protection ou de captcha, c’est un simple formulaire.