graham23s Posted November 18, 2008 Share Posted November 18, 2008 Hi Guys, in my code i can login to a forum and i try to post a private message to myself but i get the "Invalid Session. Please resubmit the form." error! functions.php <?php function curl_login($url,$data,$proxy,$proxystatus){ $fp = fopen("cookie.txt", "w"); fclose($fp); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($login, CURLOPT_COOKIESESSION, TRUE); curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($login, CURLOPT_TIMEOUT, 40); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'on') { curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($login, CURLOPT_PROXY, $proxy); } curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_HEADER, TRUE); curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); curl_setopt($login, CURLOPT_POSTFIELDS, $data); ob_start(); // prevent any output return curl_exec ($login); // execute the curl command ob_end_clean(); // stop preventing output curl_close ($login); unset($login); } function curl_grab_page($site,$proxy,$proxystatus){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'on') { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($ch, CURLOPT_URL, $site); ob_start(); // prevent any output return curl_exec ($ch); // execute the curl command ob_end_clean(); // stop preventing output curl_close ($ch); } ?> index.php <?php // INCLUDE THE FUNCTIONS FILE include("inc/inc-functions.php"); // CREDENTIALS $url = "http://www.site.org/login.php"; $data = "username=graham23s&password=milkybar&autologin=on&redirect=&login=Log+in"; $dataPM = "username=graham23s&subject=fhf&addbbcode18=%23&addbbcode20=12&helpbox=Italic+text%3A+%5Bi%5Dtext%5B%2Fi%5D++%28alt%2Bi%29&message=hf&via=&attach_sig=on&folder=inbox&mode=post&sid=$session&post=Submit"; $pmURL = "http://www.site.org/privmsg.php?mode=post&u=319462"; // EXECUTE LOGIN $dataPrint1 = curl_login($url,$data,$proxy,$proxystatus); //print $dataPrint; // SEND A PM $dataPrint2 = curl_login($pmURL,$dataPM,$proxy,$proxystatus); print $dataPrint2; ?> if i add: curl_setopt($login, CURLOPT_COOKIESESSION, TRUE); i can see what the session id is, but im not sure how to pass it through! any advice would be great cheers Graham Link to comment https://forums.phpfreaks.com/topic/133224-continuing-sessions-using-curl/ Share on other sites More sharing options...
jjacquay712 Posted November 18, 2008 Share Posted November 18, 2008 I cant help you with your code, but have you considered using the $_SESSION array? Link to comment https://forums.phpfreaks.com/topic/133224-continuing-sessions-using-curl/#findComment-693071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.