Advertisement:

Author Topic: Accessing SMF with PHP and CURL  (Read 1416 times)

Offline poshgang

  • Newbie
  • *
  • Posts: 3
Accessing SMF with PHP and CURL
« on: July 27, 2017, 09:13:16 AM »
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.

Offline poshgang

  • Newbie
  • *
  • Posts: 3
Re: Accessing SMF with PHP and CURL
« Reply #1 on: July 27, 2017, 09:15:40 AM »
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="" />

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,343
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Accessing SMF with PHP and CURL
« Reply #2 on: July 27, 2017, 09:30:34 AM »
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

Offline poshgang

  • Newbie
  • *
  • Posts: 3
Re: Accessing SMF with PHP and CURL
« Reply #3 on: July 27, 2017, 12:49:37 PM »
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.

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,343
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Accessing SMF with PHP and CURL
« Reply #4 on: July 27, 2017, 12:58:41 PM »
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