Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: anonymous001 on August 16, 2015, 03:27:20 AM

Title: SMF API smfapi_registerMember()
Post by: anonymous001 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:

<?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;
Title: Re: SMF API smfapi_registerMember()
Post by: margarett on August 16, 2015, 03:09:11 PM
Check your php error log, it should tell you what's wrong ;)
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles on August 16, 2015, 03:19:41 PM
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'
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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.
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles 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.
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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)...
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles 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.
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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?):

[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

Title: Re: SMF API smfapi_registerMember()
Post by: Shambles 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
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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...
Title: Re: SMF API smfapi_registerMember()
Post by: JBlaze 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
<?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';

?>
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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?
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 on August 19, 2015, 01:07:10 PM
Error already exists.
Can someone offer support/reproduce my error?

All the best;
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles on August 19, 2015, 01:27:01 PM
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)
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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;
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles 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');
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 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 :)
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles on August 19, 2015, 02:42:00 PM
It does work, provided the correct path is used in the "require_once"

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2F4eUyzL6.png&hash=0acd115c753af24a9eb6c6693c901a844678db31)

- and the user -

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FZerlsxL.png&hash=4238cbe0e650c9652821c81225bdfb20590b6869)

Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 on August 20, 2015, 02:38:32 PM
Please check your PMs Shambles.
Title: Re: SMF API smfapi_registerMember()
Post by: Shambles 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.
Title: Re: SMF API smfapi_registerMember()
Post by: anonymous001 on August 21, 2015, 07:09:49 AM
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.