Facebook Login with cURL

shubhamjain1

By this script you can remotely login into facebook account with your password and username and fetch/send data.

MooGeek commented: SICK! +5
6,465 Views
About the Author
<?php

/* EDIT EMAIL AND PASSWORD */
$EMAIL      = "";
$PASSWORD   = "";

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("https://login.facebook.com/login.php?login_attempt=1",true,null,"email=$EMAIL&pass=$PASSWORD");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL("https://login.facebook.com/login.php?login_attempt=1",true,$b[1],"email=$EMAIL&pass=$PASSWORD");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
    $cookie.=$d[1][$i].";";

/*
NOW TO JUST OPEN ANOTHER URL EDIT THE FIRST ARGUMENT OF THE FOLLOWING FUNCTION.
TO SEND SOME DATA EDIT THE LAST ARGUMENT.
*/
echo cURL("http://www.facebook.com/",null,$cookie,null);
?>
Member Avatar
nileshgr

Can you post a snippet to use the Facebook API using pure cURL without involving any javascript stuff ?
I wish to use the Facebook-Oauth in a project by this method.

kyrilkong 0 Newbie Poster

Any idea on how I could make good use of this wonderful looking code :)

ozkurede 0 Newbie Poster

It does not wotk, I get blank facebook login page, and not logged in.

Can u post a new solution if possible, please?

Best Reg,

ulas

Member Avatar
jogjayr

are you sure this script works? facebook has a number of hidden input fields on the login form; don't all those need to be submitted as well?

ayazoglu 0 Newbie Poster
<?php
////////////////////////////////////////
//Code By Kerim YILMAZ
//www.ayazoglu.org
////////////////////////////////////////
@$cookie_file_path = "c.txt";
// c.txt die bi dosya yapın cookie ler kayıt için..
$fp = fopen($cookie_file_path, "w");
fclose($fp);
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
$reffer = "http://www.facebook.com/login.php";
$kullaniciadin = "faceboook email";
$sifren = "şifren";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://login.facebook.com/login.php");
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, "charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&version=1.0&return_session=0&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&email=".$kullaniciadin."&pass=".$sifren."");
$html = curl_exec($ch);
$bol = explode('<head>', $html);
$oku = explode('Hesap', $bol[1]);
if($oku){
// Üyelik var işlemle
}else{
// Üyelik Yok işlemler
}
//Giriş yaptıktan sonra anasayfayı yazar
echo $bol[1;]
?>

this code very good ;)

jayapalchandran 0 Newbie Poster

when i run the above code i got the following
Cookies Required

Cookies are not enabled on your browser. Please adjust this in your security preferences before continuing.

itpankaj 0 Newbie Poster
vijay424 0 Newbie Poster

Yes you can. But there is small problem with Google Crome browser. It doesn't update the page or it doesn't execute the refresh command. You need to use extra code for that browser to get it done...

MrOBY 0 Newbie Poster

this is not working.. my account fb still disconected even after run this code..
=,="

muhammedhunkar 0 Newbie Poster

ayazoglu türk olduğun nerden belli charset= :)))))))

pozitive 0 Newbie Poster

hahaha, olsun yazmış adam işte :)
bu arada yukardaki kod 10 numara çalışıyor. son cookie yi de session da tutup sitede gezebilirsiniz.

thanks for first code.

Tùng 0 Newbie Poster

Huy Tùng

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.