SMF API smfapi_registerMember()

Started by anonymous001, August 16, 2015, 03:27:20 AM

Previous topic - Next topic

anonymous001

Dear community;

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

<?php
//include api
require_once('smf_api.php');


                
$regOptions = array(
                        
'member_name' => 'autouser',
                        
'email' => '[email protected]',
                        
'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;

margarett

Check your php error log, it should tell you what's wrong ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

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

Shambles

Quote from: jaheller on August 16, 2015, 03:27:20 AM
<?php
//include api
require_once('smf_api.php');
...


Is that the correct file to include?

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

require_once '/path/to/api/file/smf_2_api.php'

anonymous001

@margarett

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

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

Shambles

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.

anonymous001

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)...

Shambles

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.

anonymous001

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?):

[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:
<?php
//include api
require_once('smf_2_api.php');


                
$regOptions = array(
                        
'member_name' => 'autouser',
                        
'email' => '[email protected]',
                        
'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


Shambles

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

anonymous001

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...

JBlaze

Here, this will make your life much simpler.

Replace /path/to/SSI.php with the actual path to SSI.php
<?php
require_once('/path/to/SSI.php');

global 
$sourcedir;

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

$regOptions = array(
    
'member_name' => 'autouser',
    
'email' => '[email protected]',
    
'password' => 'testtest',
    
'memberGroup' => 4,
);

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

?>
Jason Clemons
Former Team Member 2009 - 2012

anonymous001

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?

anonymous001

Error already exists.
Can someone offer support/reproduce my error?

All the best;

Shambles

QuotePHP 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)

anonymous001

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;

Shambles

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');

anonymous001

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 :)

Shambles

It does work, provided the correct path is used in the "require_once"



- and the user -




anonymous001


Shambles

Before we go down that route, reupload smf_2_api.php as I think yours may be corrupted.

anonymous001

It's working now *YAY*.
Any idea why this occurs sometimes when I for example try to use
smfapi_login(8,525600);
The session gets set (user gets logged into) but I get a notice saying:
Notice: Undefined variable: cookieData in C:\xampp\htdocs\smf\smf_2_api.php on line 1909

Any idea how to fix this? I know it's not critical, notices are turned off on working mode (php config), but I think writing code that doesn't trigger any notice is the best to do.

Advertisement: