News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Accessing SMF with PHP and CURL

Started by poshgang, July 27, 2017, 09:13:16 AM

Previous topic - Next topic

poshgang

I have a forum and i would like to code a bot that does certain functions. I am having trouble loging in with curl.

Quote
 
<?php

$user = "";
$password = "";
$url = "mysite/index.php?action=login2";
$cookie="cookie.txt";

$ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_POSTFIELDS, "&user=$user&passwrd=$password&cookielength=-1&submit=Login");
   curl_setopt ($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($ch);
 
  if (curl_error($ch)) {
    echo curl_error($ch);
}
 
 
  echo $result;
 
 
 




?>



The error i get is:
Session verification failed.  Please try logging out and back in again, and then try again.

poshgang

This is what the source of my logon page is

Quote<form id="guest_form" action="mysite/index.php?action=login2" method="post" accept-charset="UTF-8"  onsubmit="hashLoginPassword(this, 'dd50ffa8c8614937a66c3e237f74f216');">
               <div class="info">Please <a href="mysite/index.php?action=login">login</a> or <a href="mysite/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="" />

vbgamer45

What SMF 2.0 version are you running?
And what are you trying to do? Do you need to login via curl to get it?  Or can you just script the functions with SMF
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

poshgang

smf 2.0.14

I would prefer to do it through php curl just because i am most familiar with that and i use it to manage the regular side of my website.

vbgamer45

You probably can but if you want your site/script as fast as possible I would use the native SMF functions/calls. Any http request you make causes slowdowns.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: