The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. February 11, 2012, 01:49:53 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: php curl login  (Read 2780 times)
java_freak
n00b
*
Offline Offline

Posts: 2


View Profile
« on: November 18, 2009, 07:16:25 AM »

hi!!
i wanna login to facebook using php curl method  Need Help ..i found a topic in this forum but found no code
i'm posting the code i've used ..i'm a beginner, so the code might be funny   Sad
i've replaced palceholders (my_email and my_password) instead of my actual username and password..

Code:
<?php 

function initial_visit()   //just to store the cookies initially set
 
{
$ckfile "G:\wamp\www\cookie.txt";
        
$ckjar "G:\wamp\www\cookiejar.txt";

$ch curl_init ("http://www.facebook.com/");
curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");


   
curl_setopt ($chCURLOPT_COOKIEJAR$ckjar);
        
curl_setopt ($chCURLOPT_RETURNTRANSFERtrue);
curl_exec($ch);
}

function 
second_visit()  //use the cookies acquired earlier to use here
{
$ckfile "G:\wamp\www\cookie.txt";
        
$ckjar "G:\wamp\www\cookiejar.txt";
        
$ch curl_init ("http://www.facebook.com/login.php");
curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");

$postfields "POSTDATA=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&session_key_only=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&lsd=_XhNM&email=my_email&pass=my_password";

        
curl_setopt ($chCURLOPT_COOKIEJAR$ckjar);
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDS,$postfields);
        
curl_setopt ($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
        
$output curl_exec ($ch);
echo $output;
}

initial_visit();
sleep(10); // simply to mock a human donno if it's required  ;D
second_visit();
?>


Any help would be appreciated...
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 9792



View Profile
« Reply #1 on: November 18, 2009, 10:49:30 AM »

Haven't tried a 'botic login to FB yet ... looking forward to this one.

Popcorn
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
java_freak
n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #2 on: November 18, 2009, 06:13:28 PM »

well. it turns out to be a simple thing that i've failed to understand  Grin..phew!! took a lotta time..
anyways, thanks perkiset..
will be  back with more questions  Wink
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 9792



View Profile
« Reply #3 on: November 18, 2009, 06:14:57 PM »

well ... so what was doing you? Was it a straight HTTP thing or something that FB was trying to inhibit you?
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #4 on: March 23, 2010, 01:23:34 AM »

my top tip list of stuff to get curl to work:

1. visit a site page first to get a cookie before trying to submit stuff / interact

2. take care to specify the right referrer

3. try turning on gzip compression - a lot of sites seem to use this as a form of browser detection / bot protection
Logged
Kovacs
Rookie
**
Offline Offline

Posts: 30



View Profile
« Reply #5 on: June 24, 2010, 02:47:51 PM »

3. try turning on gzip compression - a lot of sites seem to use this as a form of browser detection / bot protection

 Idea...
Logged

No links in signatures please
serialnoob
Journeyman
***
Offline Offline

Posts: 86


View Profile
« Reply #6 on: August 10, 2010, 04:28:33 PM »

3. try turning on gzip compression - a lot of sites seem to use this as a form of browser detection / bot protection

 Idea...

Do you mean
Code:
    $header = array(
            "Accept: text/xml,application/xml,application/xhtml+xml,
            text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
            "Accept-Language: en, en-gb;q=0.8, en;q=0.7",
            "Accept-Charset: utf-8;q=0.7,*;q=0.7",
            "Keep-Alive: 300");

/* adding  "Accept-Encoding: gzip,deflate", somewhere ? */

Logged

Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill
vibratingquickly
n00b
*
Offline Offline

Posts: 8


View Profile
« Reply #7 on: August 11, 2010, 05:36:48 AM »


Do you mean
Code:
    $header = array(
            "Accept: text/xml,application/xml,application/xhtml+xml,
            text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
            "Accept-Language: en, en-gb;q=0.8, en;q=0.7",
            "Accept-Charset: utf-8;q=0.7,*;q=0.7",
            "Keep-Alive: 300");

/* adding  "Accept-Encoding: gzip,deflate", somewhere ? */


I thing that's what herbacious meant.

On a related note, try Ruby Mechanize. The library handles cookies, redirects and more automatically. It is far easier to use than curl if you need to make multiple requests to sites, since it handles state.
« Last Edit: August 11, 2010, 06:04:49 AM by vibratingquickly » Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!