v2.5.2
Giriş yap

PHP cUrl giriş yapabiliyorum ama cookie.txt ile diğer sayfalara göz atamıyorum

siyahkalem
820 defa görüntülendi

Merhaba,
PHP cUrl le bir siteye login olabiliyorum ancak sayfalarında dolaşamıyorum. Cookie.txt dosyasına baktığımda giriş bilgileri geliyor ancak diğer sayfalarına ulaşmak istediğimde giriş yapmamışım gibi görüyor. Sizce neden olabilir?

    <?php


require 'curl.php';

$base = "https://siteadi.com/login";
$html_base = file_get_html($base);

$token  = $html_base->getElementByTagName("input[name=currentPageToken]")->getAttribute("value");
$agent  = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36";

$data = array(

    "username"     => "*******",
    "password"     => "*******"
);


//init curl
$ch = curl_init();



//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $base);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);


// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, true);

//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');


//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


//execute the request (the login)
$store = curl_exec($ch);


//the login is now done and you can continue to get the
//protected content.

//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'https://siteadi.com/profil');



//execute the request
echo $content = curl_exec($ch);

curl_close($ch);



Cevap yaz
Cevaplar (5)
orange
746 gün önce

Merhaba,

Eğer Windows kullanıyorsanız absolute path vermeniz gerekebilir.

curl_setopt ($ch, CURLOPT_COOKIEJAR, realpath('cookie.txt'));
siyahkalem
761 gün önce

Maalesef, yine giriş yapılamıyor.

abdullahx
761 gün önce

Cookie dosyalarında konumu daha net belirtmeyi deneyin

__DIR__ . DIRECTORY_SEPARATOR . 'cookie.txt';
siyahkalem
761 gün önce

Deniyorum ama yinede olmuyor. Sebebini bir türlü anlamadım

recepkaramanli61
763 gün önce

profil sayfasını çekerken dosyaya kayıt edilmiş cookie'yi şöyle kullanacaksınız,

<code>
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
</code>