Need help to autologin in forum

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
vrushali
Registered User
Posts: 1
Joined: Tue Jan 16, 2018 6:44 am

Need help to autologin in forum

Post by vrushali »

I am using below code to autologin to forum section.

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

if($user->data['is_registered'])
{
echo "Welcome " . $user->data['username']; //User is already logged in
}
else if(isset($_POST['login']))
{
$username = request_var('username', '', true);
$password = request_var('password', '', true);
$autologin = (!empty($_POST['autologin'])) ? true : false;

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

if ($result['status'] == LOGIN_SUCCESS)
{
//User was successfully logged into phpBB
$redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");

// append/replace SID
$redirect = reapply_sid($redirect);

meta_refresh(0, $redirect);
trigger_error('You have been logged in');
}
else
{
echo 'Bad Login ' . $username; //User's login failed
}
}
else
{
echo '
Please log in:<br />
<form method="POST" action="_SELF">
<p>Username: <input type="text" name="username" size="40"><br />
Password: <input type="password" name="password" size="40"><br />
Remember Me?: <input type="checkbox" name="autologin"><br />
<input type="submit" value="Submit" name="login"></p>
</form>';
}


Here $user->session_begin(); in this function getting '$request' variable as null.

function session_begin($update_session_page = true)
{
global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path;
global $request, $phpbb_container, $phpbb_dispatcher;
// Give us some basic information
$this->time_now = time();
$this->cookie_data = array('u' => 0, 'k' => '');
$this->update_session_page = $update_session_page;
var_dump($request); /////=====> This prints NULL

//Remaining code for this function.
//Note : I have not changed any thing in any phpbb forum file
}

Any kind of help is appreciated!
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Need help to autologin in forum

Post by Ger »

vrushali wrote: Tue Jan 16, 2018 6:55 am Any kind of help is appreciated!
It might help if you use code-blocks for your code and if you actually ask a question. Also state your phpBB version and other relevant info.

I see request_var though, that's deprecated in 3.1 IIRC.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Need help to autologin in forum

Post by mrgoldy »

Code: Select all

function session_begin($update_session_page = true)
{
global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path;
global $request, $phpbb_container, $phpbb_dispatcher;
// Give us some basic information
$this->time_now	= time();
$this->cookie_data	= array('u' => 0, 'k' => '');
$this->update_session_page	= $update_session_page;
var_dump($request); /////=====> This prints NULL

//Remaining code for this function.
//Note : I have not changed any thing in any phpbb forum file
}
Also, you're dumping an entire class, not a variable.
So you have to request a variable (like you're doing with the [deprecated]request_var) and that you can dump/echo/print/ w/e
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Need help to autologin in forum

Post by david63 »

It might seem a silly question, but why are you creating code to autologin when all you need do is check the "Remember me" box when you login?
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
Post Reply

Return to “phpBB Custom Coding”