Szeretnék culr-el belépni iwiw-re, de nem nagyon tudok.
Összeányolt első kód:
PHP kód:
<?php
function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
curl_close($ch);
}
$a = cURL("http://iwiw.hu/pages/user/login.jsp",true,null,"email=valami%40gmail.com&password=valami");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL("http://iwiw.hu/pages/user/login.jsp",true,$b[1],"email=valami%40gmail.com&password=valami");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
$cookie.=$d[1][$i].";";
echo cURL("http://www.iwiw.hu/",null,$cookie,null);
?>
Másik lelt kód, bár ez régi:
PHP kód:
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.domainnev.loc/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=username&password=password&act=login&Submit1=Login");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
ob_start(); // prevent any output
$buf=curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.domainnev.loc/belepve.php");
$buf2 = curl_exec ($ch);
curl_close ($ch);
echo "
".htmlentities($buf2);
még egy cucc:
PHP kód:
<?php
//...
// "böngésző" inicializálás
$ch = curl_init();
// böngésző beállításai. a legfontosabb a sütiket tároló fájl, ezt tudnia kell létrehoznia a php-nek. ezenkívül azt hazudjuk az iwiw-nek, hogy egy firefox böngésző vagyunk... :)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/path/to/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/path/to/cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5');
// bejelentkezés az iwiw-be. itt a lényeg a POST változók tartalma! (az emailcímnél a @ encode-olva van: %40)
curl_setopt($ch, CURLOPT_URL, 'http://iwiw.hu/pages/user/login.jsp?method=Login');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email=email%40cim.hu&password=JELSZO&httpslogin=false&loginradio=1');
curl_exec($ch);
// ha megvolt a bejelentkezés, le lehet kérni a kép listát. a $userid változó a felhasználó IWIW ID-je, akire kíváncsiak vagyunk
curl_setopt($ch, CURLOPT_URL, 'http://iwiw.hu/pages/image/albumgallery.jsp?userID=' . $userid . '&albumID=');
curl_setopt($ch, CURLOPT_POST, FALSE);
$html = curl_exec($ch);
// böngésző bezárás
curl_close($ch);
// egyszerűen kiírjuk a kimenetre, megfelelő headerrel
header("Content-Type: application/rss+xml; charset=utf-8");
echo $html;
?>
Könyvjelzők