Login integration

Discussion forum for MOD Writers regarding MOD Development.
Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Login integration

Post by Altutto » Mon Sep 02, 2013 1:42 pm

I tried to integrate phpbb login with an other application developed by me with this code:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'http://altutto.altervista.org/f/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup();

if ($user->data['user_id'] == ANONYMOUS)
{
   echo 'Please login!';
}

else
{
   echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>
But it gives me this message: Fatal error: Call to a member function session_begin() on a non-object on line 14

How can I correct this?

User avatar
Solidjeuh
Registered User
Posts: 522
Joined: Wed Oct 06, 2010 11:20 pm
Location: Aalst / Belgium
Name: Andy Dm
Contact:

Re: Login integration

Post by Solidjeuh » Mon Sep 02, 2013 3:24 pm

Try this:

Code: Select all

    <?php
    define('IN_PHPBB', true);
    $phpbb_root_path = './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
     
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    if($user->data['is_registered'])
    {
        //User is already logged in
    }
    else
    {
        $username = request_var('username', '', true);
        $password = request_var('password', '', true);

        $result = $auth->login($username, $password);

        if ($result['status'] == LOGIN_SUCCESS)
        {
            //User was successfully logged into phpBB
        }
        else
        {
            //User's login failed
        }
    }
    ?>
Or this:

Code: Select all

    <?php
    /**
    *
    * Login script for phpBB using username/password
    * Used for website authentication
    *
    */
    define('IN_PHPBB', true);
    $phpbb_root_path = dirname(__FILE__) . '/./';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include("common.php");
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    $username = request_var('username', '');
    $password = request_var('password', '');

    if(isset($username) && isset($password))
    {
      $auth->login($username, $password, true);
    }
    ?>
I don't suffer from insanity. I enjoy every minute of it.

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 3:36 pm

I tried both, they give the same error on the line
$user->session_begin();
"Fatal error: Call to a member function session_begin() on a non-object" :cry:

User avatar
Solidjeuh
Registered User
Posts: 522
Joined: Wed Oct 06, 2010 11:20 pm
Location: Aalst / Belgium
Name: Andy Dm
Contact:

Re: Login integration

Post by Solidjeuh » Mon Sep 02, 2013 3:40 pm

I searched for the error and found this:
viewtopic.php?t=1178965&p=6972805
I don't suffer from insanity. I enjoy every minute of it.

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 3:48 pm

Sorry, I haven't understood what I have to do.
Please, can you explain it to me?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51727
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login integration

Post by Brf » Mon Sep 02, 2013 4:22 pm

Your $phpbb_root_path needs to be the relative path from your custom script to your phpBB installation -- on the same server. You cannot use http: to load a script from another server. Otherwise you could simply load someone else's config.php and steal their password.

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 4:27 pm

I hadn't tought about that.
I modified the line of the root path as this:

Code: Select all

    $phpbb_root_path = dirname(__FILE__) . '.../.../f';
But it doesn't work anyway

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51727
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login integration

Post by Brf » Mon Sep 02, 2013 4:28 pm

That is meaningless. There is no relative path with 3dots like that.

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 4:31 pm

You're right, I corrected the code with

Code: Select all

    $phpbb_root_path = dirname(__FILE__) . '././f';

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51727
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login integration

Post by Brf » Mon Sep 02, 2013 4:46 pm

Dirname(_file_) is unnecessary and ././ is redundant

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 5:06 pm

So

Code: Select all

  $phpbb_root_path = . './f';
Is correct?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51727
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login integration

Post by Brf » Mon Sep 02, 2013 5:08 pm

That leading dot is trying to concatenate it to nothing. Otherwise I assume it is correct, assuming your phpBB is in the "f" folder from where your custom script is.

Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Login integration

Post by Altutto » Mon Sep 02, 2013 5:11 pm

So I'm removing it.
phpBB is located in /f, my script is in /test/test, should I move the directory "test" into "f"?

User avatar
Lumpy Burgertushie
Registered User
Posts: 66340
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Login integration

Post by Lumpy Burgertushie » Mon Sep 02, 2013 5:25 pm

this might help a bit:
http://www.boogiejack.com/server_paths.html

robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51727
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login integration

Post by Brf » Mon Sep 02, 2013 5:28 pm

Then your script path should be ../../f

Locked

Return to “[3.0.x] MOD Writers Discussion”

cron