Jump to content

[SOLVED] Open second page after authenticating with cURL


Gorf8083

Recommended Posts

you will have to excuse me because I am very new to using cURL.

 

I have located a script that lets me log into MySpace using cURL.  This script works fine and I can use it to log into my MySpace account and display my account homepage.  (I will post the script in just a little bit.)  But as soon as I am in my account the script seems to log out.  I am wanting to open 1 more page and store the page to strip out information.

 

Now for the fun little toy I found.

 

<?php

$cookieFile = '/tmp/mscookiejar-'.time().$randnum = mt_rand(11111, 999999);
$msUsername = '[email protected]';
$msPassword = 'Password';

//
// Log user into myspace
//
$curl_connection = curl_init("https://secure.myspace.com/index.cfm?fuseaction=login.process");

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, $cookieFile);
//curl_setopt($curl_connection, CURLOPT_VERBOSE, true);
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_REFERER, "http://www.myspace.com");
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"));

$post_string = urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$SingleSignOnHash').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$SingleSignOnRequestUri').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$nexturl').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$apikey').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$ContainerPage').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$SMSVerifiedCookieToken').'=';
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$Remember_Checkbox').'=off';
$post_string .= "&__VIEWSTATE=/wEPDwULLTIwOTI5NDgxMzlkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBTRjdGwwMCRjdGwwMCRjcE1haW4kY3BNYWluJExvZ2luQm94JFJlbWVtYmVyX0NoZWNrYm94";
$post_string .= "&NextPage=";
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$Email_Textbox').'='.urlencode($msUsername);
$post_string .= "&".urlencode('ctl00$ctl00$cpMain$cpMain$LoginBox$Password_Textbox').'='.urlencode($msPassword);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
curl_close($curl_connection);

// Find user id and name
$msIDStart = strpos($result, '{"UserId":') + 10;
$msIDEnd = strpos($result, ',"DisplayFriendId":') - $msIDStart;
$msID = substr($result, $msIDStart, $msIDEnd);

Echo $result;

?>

 

All you do is set the $msUsername and $msPassword to the account you want to log into.

See thats the problem, I am not sure how to open another page once I originally start the cURL session.  Like I said this is my first venture in using cURL, I did not write this script and I honestly don't know much about cURL at all.  All of the resources I have found about cURL are very cryptic at best, are there any other resources out there that explain cURL a bit better?

See thats the problem, I am not sure how to open another page once I originally start the cURL session.  Like I said this is my first venture in using cURL, I did not write this script and I honestly don't know much about cURL at all.  All of the resources I have found about cURL are very cryptic at best, are there any other resources out there that explain cURL a bit better?

 

I am currently attempting something similar with Curl on Craigslist. I manage to get the first page open, But since "with curl" you initialize the URL to open

$curlResults = curlURL("http://southcoast.craigslist.org/sss/");

It is hard to understand how to open additional pages. I am trying to use a regex, but still not working. 

I am currently attempting something similar with Curl on Craigslist. I manage to get the first page open, But since "with curl" you initialize the URL to open

$curlResults = curlURL("http://southcoast.craigslist.org/sss/");

It is hard to understand how to open additional pages. I am trying to use a regex, but still not working.

 

Laugh so you also understand my deliminator, I can attempt to open another page  before I initiate the curl_close($curl_connection); to close the session but its not keeping the token from the first page.

Here a quick template I made for you including the capability to save a cookie...$pages is an array with different links:

 

<?php
$ch = curl_init();
//Set options for curl session
$options = array(CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
CURLOPT_VERBOSE => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookies.txt');

//Login using POST
$options[CURLOPT_URL] = $pages['login'];
$options[CURLOPT_POST] = TRUE;
$options[CURLOPT_POSTFIELDS] = '.tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=7bblcjh5b532n&.v=0&.challenge=ejb1QmTyEDGcyJg0ES5oxuI4XQj3&.yplus=&.emailCode=&';
$options[CURLOPT_FOLLOWLOCATION] = TRUE;
curl_setopt_array($ch, $options);
$login = curl_exec($ch);

//Next page
$options[CURLOPT_URL] = $pages['redirect'];
$options[CURLOPT_FOLLOWLOCATION] = TRUE;
curl_setopt_array($ch, $options);
$redirect = curl_exec($ch);


curl_close($ch);
?>

 

 

I am currently attempting something similar with Curl on Craigslist. I manage to get the first page open, But since "with curl" you initialize the URL to open

$curlResults = curlURL("http://southcoast.craigslist.org/sss/");

It is hard to understand how to open additional pages. I am trying to use a regex, but still not working.

 

Laugh so you also understand my deliminator, I can attempt to open another page  before I initiate the curl_close($curl_connection); to close the session but its not keeping the token from the first page.

 

Yep, I have been asking for a week now how to accomplish this, but my cries continue to go unanswered as I am guessing most people are not familiar with Curl?

Here a quick template I made for you including the capability to save a cookie...$pages is an array with different links:

 

<?php
$ch = curl_init();
//Set options for curl session
$options = array(CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
CURLOPT_VERBOSE => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookies.txt');

//Login using POST
$options[CURLOPT_URL] = $pages['login'];
$options[CURLOPT_POST] = TRUE;
$options[CURLOPT_POSTFIELDS] = '.tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=7bblcjh5b532n&.v=0&.challenge=ejb1QmTyEDGcyJg0ES5oxuI4XQj3&.yplus=&.emailCode=&';
$options[CURLOPT_FOLLOWLOCATION] = TRUE;
curl_setopt_array($ch, $options);
$login = curl_exec($ch);

//Next page
$options[CURLOPT_URL] = $pages['redirect'];
$options[CURLOPT_FOLLOWLOCATION] = TRUE;
curl_setopt_array($ch, $options);
$redirect = curl_exec($ch);


curl_close($ch);
?>

 

You are the man... that was just the push I needed to get me in the right direction.  I used this...

 

curl_setopt($curl_connection, CURLOPT_URL, $NextURL );
$result = curl_exec($curl_connection);

 

to open a second connection and that works fine.  I think you so much... I will go ahead and mark this solved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.