Hi guys,
I need a help here. I’m trying to create a script with CURL PHP to login and post something. So it will have 2 or more pages to follow before the real posting.
I’ve search the php.net and created a code below. However, the return from CURL is just the login page for both execution, and it’s not even logged in.
I’ve tried to:
– close the curl after 1st exec and open it again at 2nd –> no result
– put curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); –> no result
Any help?
Regards,
[code]<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER,’http://www.site.com’);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, “/cookie.txt”);
curl_setopt($ch, CURLOPT_URL,”http://www.site.com/login/login.php”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “username=user&password=pass”);
curl_exec ($ch);
curl_setopt($ch, CURLOPT_COOKIEFILE, “/cookie.txt”);
curl_setopt($ch, CURLOPT_URL,”http://www.site.com/folder/save.php”);
curl_exec ($ch);
curl_close ($ch);
?>