Connecting to Simple Machine Forum with CURL and PHP

219 Views Asked by At

Here is the source for login form for the smf i am trying to login to

 <form id="guest_form" action="http://example.com/index.php?action=login2" method="post" accept-charset="UTF-8"  onsubmit="hashLoginPassword(this, '828560f91ef51ab12e80def32be06ad4');">
                        <div class="info">Please <a href="http://example.com/index.php?action=login">login</a> or <a href="http://example.com/index.php?action=register">register</a>.</div>
                        <input type="text" name="user" size="10" class="input_text" />
                        <input type="password" name="passwrd" size="10" class="input_password" />
                        <select name="cookielength">
                            <option value="60">1 Hour</option>
                            <option value="1440">1 Day</option>
                            <option value="10080">1 Week</option>
                            <option value="43200">1 Month</option>
                            <option value="-1" selected="selected">Forever</option>
                        </select>
                        <input type="submit" value="Login" class="button_submit" /><br />
                        <div class="info">Login with username, password and session length</div>
                        <input type="hidden" name="hash_passwrd" value="" />
                    </form>

Here is the php code i came up with:

<?php
$user = "test"; 
$pass = "test"; 
$url="http://www.jasper88.5gbfree.com/index.php?action=login2"; 


$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' );
$referer = "http://www.jasper88.5gbfree.com";




$postdata = "user=$user&passwrd=$pass&cookielength=-1&submit=Login";


$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_FAILONERROR, false );
curl_setopt ($ch, CURLOPT_TIMEOUT, false );
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ($ch, CURLOPT_USERAGENT, $curl_useragent );
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_COOKIESESSION, true );
curl_setopt ($ch, CURLOPT_URL, $url);  
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, "/cok4.txt"); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, "/cok4.txt"); 
curl_setopt ($ch, CURLOPT_VERBOSE, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, true); 
$result = curl_exec ($ch); 


echo $result;
if (curl_error($ch)) {
    echo curl_error($ch);
}






?>

I get this error: Session verification failed. Please try logging out and back in again, and then try again.

Can anyone help me? The server is mine and login works if you want to try code.

0

There are 0 best solutions below