Hello, I try to post with curl to SMF. Everything is ok, but when i try to send pm i get "Please Login". I guess its cookie problem. login.php <?php // login.php $url = "http://www.xxx.com/forum/login2/"; $postfields = "user=xxx&passwrd=xxx&cookieneverexp=on"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_COOKIEJAR, "C:\wamp\www\cookie.txt"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); ?> PHP: pm.php <?php // pm.php $url = "http://www.xxx.com/forum/pm/?sa=send2"; $post = "to=reptile&subject=Test&message=test&Submit=Send"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "C:\wamp\www\cookie.txt"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $out = curl_exec($ch); curl_close($ch); ?> PHP: It is working, logining , going to pm page, writing message to blanks, click to send, then "Please Login". Thanks.
Check the cookie.txt file you're writing to. Are the cookies being written to it? Try including both the cookiejar and cookiefile options in both scripts.
Yes cookies are writing but it isnt still working. I dont know what can i do. I have written some forums but i cant get any reply.
Should CURLOPT_POST be true or 1? I'd also add a few things to your curl options: // Add a nice common useragent $curl_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'; $curl_httpheader = array( 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'Accept-Language: en-us,en;q=0.5', 'Accept-Encoding: gzip,deflate', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' ); $curl_referer = 'http://www.xxx.com/'; curl_setopt( $ch, CURLOPT_FAILONERROR, 0 ); curl_setopt( $ch, CURLOPT_TIMEOUT, 0 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_USERAGENT, $curl_useragent ); curl_setopt( $ch, HTTPHEADER, $curl_httpheader ); curl_setopt( $ch, CURLOPT_REFERER, $curl_referer ); curl_setopt( $ch, CURLOPT_VERBOSE, false ); curl_setopt( $ch, CURLOPT_COOKIESESSION, true ); Dos that make a difference? PHP:
You dont need to close the curl session in pm page, just go in one shot that will solve your problem.