Tego sie obawialem:)
Oto kod. Pewnie sa w nim glupoty, ale w koncu dopiero sie ucze:) Oczywiscie te wszystkie "echo" itp to tylko moje raportowanie cobym wiedzial co sie dzieje:0
<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.xxxx.cos/login.php?action=dologin');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'pass=haselko&user=uzytkownik&login_pass=0&remember=0');
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($c, CURLOPT_REFERER, 'http://www.xxxx.cos/login.php');
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt
($c, CURLOPT_COOKIEFILE
, dirname(__FILE__) . '/'.$cookie_file); curl_setopt
($c, CURLOPT_COOKIEJAR
, dirname(__FILE__) . '/'.$cookie_file);
$page = curl_exec($c);
curl_close($c);
foreach ($headers as $a) {
if (strpos($a, 'PHPSESSID') > 1
) { $poz = strpos($a, 'PHPSESSID'); $sid = substr($a, $poz + 10
, 32
); }
}
echo('SESJA : '.$sesid.' / '.$sid.'<br><br>');
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.xxxx.cos/index.php?sid='.$sid);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($c, CURLOPT_REFERER, 'http://www.xxxx.cos/login.php');
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt
($c, CURLOPT_COOKIEFILE
, dirname(__FILE__) . '/'.$cookie_file); $page = curl_exec($c);
curl_close($c);
echo 'Wynik: <br>'.$page; ?>
Dodam jeszcze naglowki jakie zwraca pierwsze wywolanie cUrla:
HTTP/1.1 302 Found
Date: Fri, 15 Jan 2010 15:08:28 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.5 with Suhosin-Patch
X-Powered-By: PHP/5.2.6-3ubuntu4.5
Set-Cookie: PHPSESSID=99c70f0da9f1f4989f1364535c2e36ee; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: uname=uzytkownik; expires=Fri, 22-Jan-2010 15:08:28 GMT
Set-Cookie: realm_id=deleted; expires=Thu, 15-Jan-2009 15:08:27 GMT
Set-Cookie: p_hash=haselko; expires=Fri, 22-Jan-2010 15:08:28 GMT
Location: index.php
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html
a to zwraca drugie wywolanie cUrla:
HTTP/1.1 302 Found
Date: Fri, 15 Jan 2010 15:08:28 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.5 with Suhosin-Patch
X-Powered-By: PHP/5.2.6-3ubuntu4.5
Set-Cookie: PHPSESSID=2dc35bf63d58ad0a8dce799f84a5a128; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: login.php
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html