pull data from "require login" page with curl
Posted: Wed Feb 23, 2011 7:33 pm
Hi,
So as my topic says, I want to login to a web site and pull data from it, I wrote the follow cUrl script that get 301, and I cant find why...
If some one can check my code out and point on my mistake I will be greatful, thanks guys.
The code goes like this>
entering the index pages, to get the session cookie.
login by posting the requested fields to the "action page"
and grab the data from the "require login" page.
thanks again.. =]
So as my topic says, I want to login to a web site and pull data from it, I wrote the follow cUrl script that get 301, and I cant find why...
If some one can check my code out and point on my mistake I will be greatful, thanks guys.
The code goes like this>
entering the index pages, to get the session cookie.
login by posting the requested fields to the "action page"
and grab the data from the "require login" page.
thanks again.. =]
Code: Select all
<?php
//
$pages = array('home' =>
'http://www.micropay.co.il/website/',
'login' =>
'http://www.micropay.co.il/WebSiteProc.php',
'data' =>
'http://www.micropay.co.il/Admin/');
$ch = curl_init();
//Set options for curl session
$options = array(CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => False,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookies.txt');
//Hit home page for session cookie
$options[CURLOPT_URL] = $pages['home'];
curl_setopt_array($ch, $options);
$empty = curl_exec($ch);
echo '______________________________________________________________________________________________________________';
//Login
$options[CURLOPT_URL] = $pages['login'];
$options[CURLOPT_POST] = TRUE;
$options[CURLOPT_CURLOPT_REFERER] = 'www.micropay.co.il/website/Index.php';
$options[CURLOPT_POSTFIELDS] = 'userName=xxxx&userPass=xxxx&act=login&formReturn=1&post=1&refURL=www.micropay.co.il/website/Index.php&submit=';
$options[CURLOPT_FOLLOWLOCATION] = TRUE;
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
echo '______________________________________________________________________________________________________________';
//Hit data page
// $options[CURLOPT_FOLLOWLOCATION] = TRUE;
$options[CURLOPT_URL] = $pages['data'];
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
//Output data
echo $data;
//Close curl session
curl_close($ch);
?>