Hello, I need some help with CURL.
What I would like to achieve is to enter a restricted area of my site through POST authentication and then go to a second URL in order to update something in my database everytime this script I am writing is called.
Basically there is an administrator/index.php page that has the log in form and then there is a administrator/index2.php page that has the options. By clicking on one of those options the database is updated. What I have been trying to do for hours now is to log in to index.php (which normally would direct me to index2.php (that's what the index.php page is coded to do) and after that to go to the URL of index2.php that performs the update.
Here is what I have so far:
// Administrator area LOGIN
$url2 = 'http://www.chaindlk.com/content/administrator/index.php';
$urlstring2 = 'usrname=MY-USERNAME-HERE&pass=MY-PASSWORD-HERE&submit=Login';
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch2, CURLOPT_VERBOSE, 1);
curl_setopt($ch2, CURLOPT_URL,$url2);
curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT, 9);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $urlstring2);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch2, CURLOPT_MAXREDIRS, 0);
curl_setopt($ch2, CURLOPT_REFERER, 'http://www.chaindlk.com/content/administrator/index.php');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$data2 = curl_exec($ch2);
curl_error($ch2);
curl_close($ch2);
if ( substr_count(strtolower($data2), strtolower("<script>document.location.href='index2.php';</script>")) >= 1 ) {
//echo "<script>alert('so far so good');</script>";
$url3 = 'http://www.chaindlk.com/content/administrator/index2.php?option=com_comprofiler&task=syncUsers';
$urlstring3 = 'option=com_comprofiler&task=syncUsers';
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_VERBOSE, 1);
curl_setopt($ch3, CURLOPT_URL,$url3);
curl_setopt($ch3, CURLOPT_HEADER, 0);
//curl_setopt($ch3, CURLOPT_HTTPGET, 1);
curl_setopt($ch3, CURLOPT_POST, 1);
curl_setopt($ch3, CURLOPT_POSTFIELDS, $urlstring3);
curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch3, CURLOPT_REFERER, 'http://www.chaindlk.com/content/administrator/index2.php?option=com_comprofiler&task=tools');
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
$data3 = curl_exec($ch3);
curl_error($ch3);
curl_close($ch3);
}
Well if I uncomment the line
echo "<script>alert('so far so good');</script>
for debugging I actually see that message which means I have successfully logged in. Once logged in though I can't seem to go to the second url because the system considers me logged out for some reason...
I have also tried moving the curl_close($ch2); after the if statement in case (I wasn't sure) the curl $ch3 has to be executed within the $ch2 (before the $ch2 is closed), but that didn't work either...
Does anybody have any ideas?
I'd appreciate any input...
Are the sessions screwing with me?
All I'd really like to know (generally speaking) is if I can, within a CURL operation execute a second CURL operation, or, to put it in different words, if once I have accesses a page through CURL I can access a secong page through CURL maintaining the authentication going...
Thanks a lot...