Jump to content

login to website, screen scraping, curl and snoopy not working


blitz2190

Recommended Posts

ok so I have spent the better part of 3 days trying to figure this out i have a script which needs to periodically sign into a website and retrieve data. The login is a simple post. the pages involved in login proccess are sitename.com/index.php which then post to sitname.com/myaccount.php to check variables.

 

first i thought this would be a good job for curl. i tried the script below, it logged in and brought me to the myaccount page but then any attempt a trying to retrieve another page in that site using the same curl connection just brought me back to the my account page. i checked headers and they are slightly different,  mainly cookie info would like to know how to fix this, but why would login work but other pages not.

 

<?php
$ch = curl_init();

// login or index.php
curl_setopt($ch, CURLOPT_URL, 'http://www.somesite.com/index.php');

curl_setopt ($ch, CURLOPT_POST, 1);

// username and password to send
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=myuser&password=mypass');

curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt')

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, curlopt_followlocation,1);

// fire first request to login
$login = curl_exec ($ch);

// Page from hich to pull data
curl_setopt($ch, CURLOPT_URL, 'http://www.somesite.com/world.php');

// get data
$content = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch);

echo $content;
?>

 

when i echo $content i get the myaccount.php page because it was redirected back to that. i tried turning curlopt_followlocation off but then login doesn't work

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.