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 » Tue Jan 16, 2018 6:55 am

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
Recognised Extension Developer
Posts: 1418
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Need help to autologin in forum

Post by Ger » Thu Jan 18, 2018 12:24 pm

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 and Modern Quote

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

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Need help to autologin in forum

Post by posey » Thu Jan 18, 2018 1:38 pm

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
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
david63
Jr. Extension Validator
Posts: 14112
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Need help to autologin in forum

Post by david63 » Thu Jan 18, 2018 7:04 pm

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!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 3 guests