External login to XenForo from a PHP site

aqua-calc

New member
Hello,

Is there a documented way to implement "login" to XenForo from a PHP site?

I've searched the forum but found only one original post without any reply.

Thank you!
 
What do you mean by login would be the first question.

You could easily post the relevant auth details to the login script, get the session ID and set the cookie yourself, however I don't think that's what you want to do.
 
I'd like to be able to access the logged-in user name, group name, etc... from within my own PHP web site.

And to be able to provide login and logout links and/or custom web pages from that same PHP website.

Thank you!
 
I'd like to be able to access the logged-in user name, group name, etc... from within my own PHP web site.

And to be able to provide login and logout links and/or custom web pages from that same PHP website.

Thank you!

Why? Can't you implement your own website into XenForo? It would make things 1000x easier :)

I guess the easiest way to do it would be to make XenForo take cookies from the same domain as the main site (I'm already assuming it's on the same domain, so that's no too easy).

You could either link to the XF login form, or simply request the login details, check them yourself with the XF classes and set the cookie, or get the login details and post them to the XenForo login, then set the cookies you get back to the users browser.

You could then include the XenForo system in your PHP, and use it to get the relevant details.

Liam
 
Thank you Liam!

Unfortunately, I don't have access to XF classes since I don't own an XF license. I'm thinking of switching away from phpBB forum, and am looking for an alternative.

Thank you again.
 
I can tell you that we went through this on our PHP/CodeIgniter application and it took over 30 hours of development to get external logins working with XenForo, and still, accessing the AdminCP requires a kludgy workarond.

Here's my thread about what it took to get this working:
http://xenforo.com/community/threads/login-logout-register-from-outside-xenforo.65878/

and here's my Suggestion thread asking for XenForo to add external login support:
http://xenforo.com/community/threads/xenforo-login-api-for-third-party-scripts.67696/


XenForo needs to provide a way for a third party script to say "This user is logged in". Not, here's the user's password, let's juggle hashing algorithms and go ten rounds. Just, this user (e-mail address) is logged in so get over it!

SMF, a free forum, provides exactly this functionality through a third party script. We got external logins completely working in less than 2 hours. However we wanted to use a professional forum and so endured rewriting all this in XenForo.
 
I'm looking to migrate to a professional board as well.

Thank you for referencing the above two threads -- I will review them carefully.

At present I'm using phpBB -- (a few years ago) it took less than an hour to read a relevant phpBB thread and to implement code into my website with which to get user status, name, etc...

I wish that XF would offer a development or a trial license, so I could try to implement new or test existing code first.

Best,

Alex.
 
Also interested to find a simple script to do it.

If a XentForo developer could tell us a simple script like this, it would be really helpful as it seems that it is requested often on the forum...:unsure::cool:

With PHPBB it is easy:
PHP:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
PHP:
<form method="post" action="forum/ucp.php?mode=login">
<label for="username">Username: </label> <input type="text" name="username" id="username" size="40" /><br /><br />
<label for="password">Password: </label><input type="password" name="password" id="password" size="40" /><br /><br />
<label for="autologin">Remember Me?: </label><input type="checkbox" name="autologin" id="autologin"  /><br /><br />
<input type="submit" value="Log In" name="login" />
<input type="hidden" name="redirect" value="../index.php" />
</form>
As explained HERE> https://www.phpbb.com/community/viewtopic.php?f=71&t=643075
 
Also interested to find a simple script to do it.

If a XentForo developer could tell us a simple script like this, it would be really helpful as it seems that it is requested often on the forum...:unsure::cool:

With PHPBB it is easy:
PHP:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
PHP:
<form method="post" action="forum/ucp.php?mode=login">
<label for="username">Username: </label> <input type="text" name="username" id="username" size="40" /><br /><br />
<label for="password">Password: </label><input type="password" name="password" id="password" size="40" /><br /><br />
<label for="autologin">Remember Me?: </label><input type="checkbox" name="autologin" id="autologin"  /><br /><br />
<input type="submit" value="Log In" name="login" />
<input type="hidden" name="redirect" value="../index.php" />
</form>
As explained HERE> https://www.phpbb.com/community/viewtopic.php?f=71&t=643075

Oh man this brings back memories. Phpbb, those were the days. I used that code snippet a lot. Shame to hear it being much more difficult for XF.
 
These cover your first question (access XF logged in data in PHP):
https://xenforo.com/community/threads/how-can-i-get-username-of-logged-user-on-php.141894/
https://xenforo.com/community/threads/how-to-check-login-status-outside-xenforo.141352/

This partially covers your second question (login/logout) but handles registrations, I figure you can get a login example by looking at the files and it should be fairly similar to this:
https://xenforo.com/community/threads/how-to-provision-a-new-user-via-external-script.141206/
 
Back
Top Bottom