Advertisement:

Author Topic: SMF API smfapi_registerMember()  (Read 11108 times)

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
SMF API smfapi_registerMember()
« on: August 16, 2015, 03:27:20 AM »
Dear community;

I'm using the SMF API script (not the "REST" api script) for registering some users into the smf db.
My code:

Code: [Select]
<?php
//include api
require_once('smf_api.php');


                
$regOptions = array(
                        
'member_name' => 'autouser',
                        
'email' => 'e@mail.de',
                        
'password' => 'testtest',
                        
'memberGroup' => 4,
                );

$userid smfapi_registerMember($regOptions);

echo'user created ' $userid ;


?>


For some reason, the screen stays white while running the script. Any idea why this occurs? Is there any page where I can see all options for the registration ($regOptions) array? Like privacy settings, user title etc. etc.

All the best;

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: SMF API smfapi_registerMember()
« Reply #1 on: August 16, 2015, 03:09:11 PM »
Check your php error log, it should tell you what's wrong ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #2 on: August 16, 2015, 03:19:41 PM »
Code: [Select]
<?php
//include api
require_once('smf_api.php');
...

Is that the correct file to include?

http://wiki.simplemachines.org/smf/SMF_API

Code: [Select]
require_once '/path/to/api/file/smf_2_api.php'

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #3 on: August 16, 2015, 03:30:21 PM »
@margarett

It says line XXX in the smf api script -.-

@Shambles
Yes i just renamed it. Path is correct.

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #4 on: August 16, 2015, 04:10:47 PM »
Quote from: jaheller
@margarett

It says line XXX in the smf api script -.-

That doesn't look like a php error log entry - I've never seen "-.-" as an error.

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #5 on: August 17, 2015, 01:21:49 AM »
Where's my fault while using the SMF API?
I don't understand where I made a mistake, did I need to send more fields, in the array, are some needed (I think only username, email and password are needed)...

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #6 on: August 17, 2015, 03:28:24 AM »
Quote from: jaheller
@margarett

It says line XXX in the smf api script -.-

What is the actual error message? What you posted is not an error message.

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #7 on: August 17, 2015, 01:47:08 PM »
Here we go;

Error code (any idea why I need to extract error message from apache server logs?, need I to activate a "debug" modus inside smf to be able to display errors in browser?):
Code: [Select]
[Mon Aug 17 12:32:52.169922 2015] [:error] [pid 3649] [client 91.40.42.165:63030] PHP Parse error:  syntax error, unexpected 'return' (T_RETURN) in  /var/www/html/smf/smf_2_api.php on line 517

My code:
Code: [Select]
<?php
//include api
require_once('smf_2_api.php');


                
$regOptions = array(
                        
'member_name' => 'autouser',
                        
'email' => 'e@mail.de',
                        
'password' => 'testtest',
                        
'memberGroup' => 4,
                );

                                
$userid smfapi_registerMember($regOptions);

                                echo
'user created ' $userid ;


?>


I attached the API script for easier testing/debugging, if you want to help me ;).
-Looking forward to get some help, I don't understand what I'm doing wrong :P


Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #8 on: August 17, 2015, 02:04:25 PM »
I don't believe that error is emanating from the file you attached. I thought it a little suspicious when you initially used smf_api.php then said you'd renamed it to smf_2_api.php


Get a proper copy of smf_2_api.php and try it again.


http://www.simplemachines.org/community/index.php?topic=453008.0

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #9 on: August 17, 2015, 02:12:46 PM »
I already did, this in my code (see above) to get sure this won't be the failure...any idea what's the reason for the error?
Can you use the API if yes, how did you register a user? I don't be sure where's the fault is located...

Offline JBlaze

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,158
  • Gender: Male
    • @fragicide on Twitter
Re: SMF API smfapi_registerMember()
« Reply #10 on: August 17, 2015, 02:34:27 PM »
Here, this will make your life much simpler.

Replace /path/to/SSI.php with the actual path to SSI.php
Code: [Select]
<?php
require_once('/path/to/SSI.php');

global 
$sourcedir;

require_once(
$sourcedir '/Subs-Members.php');

$regOptions = array(
    
'member_name' => 'autouser',
    
'email' => 'e@mail.de',
    
'password' => 'testtest',
    
'memberGroup' => 4,
);

if (
registerMember($regOptions))
    echo 
'User created';

?>
Jason Clemons
Former Lead Customizer/Support Specialist
Twitter | Facebook | Instagram

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #11 on: August 17, 2015, 02:44:02 PM »
But I need to be able to set login cookie to a member (set session via script) and redirect users after a login made by my script to the forum.
I was told to use the API, not the SSI, what should I do?

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #12 on: August 19, 2015, 01:07:10 PM »
Error already exists.
Can someone offer support/reproduce my error?

All the best;

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #13 on: August 19, 2015, 01:27:01 PM »
Quote
PHP Parse error:  syntax error, unexpected 'return' (T_RETURN) in  /var/www/html/smf/smf_2_api.php on line 517

So what's on line 517 of that file? (include 5 lines before plus 5 after)

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #14 on: August 19, 2015, 01:37:59 PM »
I attached the smf_api script some posts before. It's strange as hell, the line is a comment, did the PHP interpreter doesn't jump over this lines? I'm not sure how to be able to get this problem debugged.
All I need to do is:
-register user ->not implemented in my project (I was told to use the API for this)
-log a user into forum (set cookie/session) ->not implemented in my project (I think I must use API too)
-log out a user (unset cookie/session) ->not implemented in my project (I think I must use API too)
-sent PM to a user ->IMPLEMETED using the SSI
-check if a user is logged into -> IMPLEMENTED (['user']['is_logged'])) SSI

Can somebody help me, to get the register user function implemented? I just need to be able to register a user into database (username, email, password, usergroup...), getting the ID of the registered user back, as the API told me to do would be great.

All the best;

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #15 on: August 19, 2015, 01:41:34 PM »
That error is not coming from the file you attached - I'm convinced you're not picking up the correct file.

Change the path of the includes to the full path, eg:

require_once('fullpath/smf_2_api.php');

Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #16 on: August 19, 2015, 02:11:53 PM »
First of all, thanks for your post Shambles ;), feels good to get support.
I attached my script + the api I used to this post. As you may see, the names I used to include the api is correct. I have no idea why this error occurs, can you reproduce?

All the best friends :)

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #17 on: August 19, 2015, 02:42:00 PM »
It does work, provided the correct path is used in the "require_once"



- and the user -




Offline jaheller

  • Semi-Newbie
  • *
  • Posts: 57
Re: SMF API smfapi_registerMember()
« Reply #18 on: August 20, 2015, 02:38:32 PM »
Please check your PMs Shambles.

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: SMF API smfapi_registerMember()
« Reply #19 on: August 20, 2015, 06:00:59 PM »
Before we go down that route, reupload smf_2_api.php as I think yours may be corrupted.