Forum Moderators: coopster

Message Too Old, No Replies

Remote Login

CURL remote Login Problem

         

bytepower

7:49 am on Aug 19, 2006 (gmt 0)

10+ Year Member



Hello

I m working on a module where i want to write a script which when run should allow me to login to a perticular site, which i call remote login (dont know if its right or wrong).
Can we do this in PHP?
I heard something called CURL...can we do it using this?

e.g.
suppose i have www.yahoo.com
and i want to login to yahoo from my program..may be passing some username and password in a string and then I want to retrieve inner page content.
I have valid username and password of the site I want to work.

Please Guide me people.

Thanking you in advance.

akany

9:01 am on Aug 19, 2006 (gmt 0)

10+ Year Member



$url = 'https://login.yahoo.com/config/login';
$string = '.tries=2&.src=siteex&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=a4sitsd2ec90f&.v=0&.challenge=KXJZgnaquGWzb7kNoDVpBuPmNBSf&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.done=targetsitegooeshere&login=usernamegoeshere&passwd=passwordgoeshere&.persistent=n';

$ch = curl_init();
$agent=$_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$data = curl_exec($ch);

Yahoo sometimes doublechecks your password, so you might want to open a second curl session after the first one, and send the same string to $url = 'https://login.yahoo.com/config/login_verify2'; ... just to make sure ;-)

coopster

3:59 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A link to the PHP manual pages for curl [php.net] may be helpful as well.

Welcome to WebmasterWorld, both of you ;)