tags:

views:

187

answers:

3

I've never done something like this before...I'm trying to log into swagbucks.com and get retrieve some information, but it's not working. Can someone tell me what's wrong with my script?

<?php
$pages = array('home' =>
'http://swagbucks.com/?cmd=home',
           'login' =>
'http://swagbucks.com/?cmd=sb-login&amp;from=/?cmd=home',
           'schedule' =>
'http://swagbucks.com/?cmd=sb-acct-account&amp;display=2');
$ch = curl_init();
//Set options for curl session
$options = array(CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; `rv:1.9.2) Gecko/20100115 Firefox/3.6',`
         CURLOPT_HEADER => TRUE,
         //CURLOPT_RETURNTRANSFER => TRUE,
         CURLOPT_COOKIEFILE => 'cookie.txt',
         CURLOPT_COOKIEJAR => 'cookies.txt');


//Hit home page for session cookie
$options[CURLOPT_URL] = $pages['home'];
curl_setopt_array($ch, $options);
curl_exec($ch);

//Login
$options[CURLOPT_URL] = $pages['login'];
$options[CURLOPT_POST] = TRUE;
$options[CURLOPT_POSTFIELDS] = '[email protected]&pswd=jblake&persist=on';
$options[CURLOPT_FOLLOWLOCATION] = FALSE;
curl_setopt_array($ch, $options);
curl_exec($ch);

//Hit schedule page
$options[CURLOPT_URL] = $pages['schedule'];
curl_setopt_array($ch, $options);
$schedule = curl_exec($ch);

//Output schedule
echo $schedule;

//Close curl session
curl_close($ch);
?> 

But it still doesn't log me in. What's wrong?

A: 

try to echo each request to see if something went wrong. (enabling CURLOPT_RETURNTRANSFER)

Dario
Thanks, I tried that and found I was requesting the wrong file...whoops.
motionman95
A: 

It works for me with "persist=1" , not "persist=on" :

$options[CURLOPT_POSTFIELDS] = '[email protected]&pswd=jblake&persist=on'; // doesn't work
$options[CURLOPT_POSTFIELDS] = '[email protected]&pswd=jblake&persist=1'; // works
$options[CURLOPT_POSTFIELDS] = '[email protected]&pswd=jblake'; // also works
a1ex07
+1  A: 

I suggest you to use

curl_setopt($ch, CURLOPT_COOKIEFILE, '/dev/null');

This way cookies are stored internally in-memory without the need of a separated file.

Andrea Zilio