$request-> problems

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
dgivens69
Registered User
Posts: 1
Joined: Fri Feb 19, 2016 5:13 pm

$request-> problems

Post by dgivens69 » Fri Feb 19, 2016 5:22 pm

I am using the following code to login to my forum.

<?php
/* Start of Forum cookie create */
define('IN_PHPBB', true);
$phpbb_root_path = './forum/'; //the path to your phpbb relative to this script
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$f_name = $_SESSION["f_name"];
$f_pass = $_SESSION["f_pass"];
$username = request_var('username', $f_name);
$password = request_var('password', $f_pass);

if(isset($username) && isset($password)) {
$result=$auth->login($username, $password, true);
if ($result['status'] == LOGIN_SUCCESS) {
echo "You're logged in"; exit;
}
else {
echo $user->lang[$result['error_msg']]; exit;
}
}
/* End of Forum cookie create */
?>

If I hard code the username/password in and run it it work fine but if, as I need to do live, I include it within my website login I get this error.

Fatal error: Call to a member function header() on null in /home/motor/public_html/forum/phpbb/session.php on line 228

I have spent days trying to work out where or what code could be clashing, so any help would be good.

drg

User avatar
gn#36
Translator
Posts: 185
Joined: Fri Oct 13, 2006 1:16 pm
Contact:

Re: $request-> problems

Post by gn#36 » Fri Feb 19, 2016 9:37 pm

I would assume the backtrace is useful in this case, to see where it actually came from when it crashes. You should enable debug mode.

It seems the request class is not properly initialized, when the user session is started, because it tries to find the global variable $request, which is null. So it seems this already crashes at $user->session_begin(), but the real error is that $request does not get instantiated. With the exception of the root path, your code is identical to the start of faq.php up to this call, so this should work, unless your root path is incorrect or you call this file from another php file, in which case that file might be responsible for funky stuff going on. I don't see how there would be a difference between testing with hardcoded variables or not since the execution does not even seem to get this far.

btw.: Your code becomes more readable, if you use code tags: [code=php] and  [ /code ] (without the spaces).
German Support Team Member • http://www.phpbb.deMy Extensions in the CDBMy Extensions on Github • Contact with caos is inavoidable but no catastrophy if you keep an overview.

Post Reply

Return to “Extension Writers Discussion”