problem in checking login status

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

problem in checking login status

Post by emosbat » Sat Jul 27, 2013 8:51 am

my forum located in: forum.domain.com
my site: http://www.domain.com

when I use this code in my site always get ANONYMOUS:

Code: Select all

// phpBB inclusion protection
define('IN_PHPBB', true);
define('DEBUG', false);
define('DEBUG_EXTRA', false);
error_reporting(0);

$phpbb_root_path = FORUM_PATH;
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if ($user->data['user_id'] == ANONYMOUS) {
   $phpbblogin=FALSE;
} else {
   $phpbblogin=$user->data['username_clean'];
}

can not find where is the problem?

edit:
is it for Cookie Domain? it is forum.domain.com

User avatar
Tom
Former Team Member
Posts: 2665
Joined: Tue Jun 20, 2006 2:12 am
Name: Tom Catullo
Contact:

Re: problem in checking login status

Post by Tom » Sat Jul 27, 2013 9:39 am

You have a line that defines the phpBB root path like so:

Code: Select all

$phpbb_root_path = FORUM_PATH;
Vanilla phpBB does not have a FORUM_PATH constant defined. Do you have such a constant defined on your forum? If not, then your code likely cannot find the common.php file, as the $phpbb_root_path variable is being set to an undefined constant — and you wouldn't even know that the file couldn't be found because you have PHP error reporting disabled.
Tom Catullo - Former Moderator Team Member
phpBB3 Smiley Pak Generator | Legend Repositioning MOD | My GitHub | My Site

User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: problem in checking login status

Post by emosbat » Sat Jul 27, 2013 9:42 am

yes it is defined in main script as path of forum

User avatar
Tom
Former Team Member
Posts: 2665
Joined: Tue Jun 20, 2006 2:12 am
Name: Tom Catullo
Contact:

Re: problem in checking login status

Post by Tom » Sat Jul 27, 2013 9:48 am

emosbat wrote:yes it is defined in main script as path of forum
I'm not quite sure I know what you mean by "main script". Is the code you posted in your original post the entire contents of the file, or just a portion of the file? If it's the entire contents of the file, then I don't see where the FORUM_PATH constant could be defined anywhere, as no external files are called for inclusion except for common.php, which may not even have the correct path specified (if my theory is correct). From the looks of it, however, it seems that the code you posted is just a part of a file with much more code involved.

I highly suggest removing the error_reporting(0); line and trying to run the file again, just in case you actually have a PHP error occurring behind the scenes. ;)
Tom Catullo - Former Moderator Team Member
phpBB3 Smiley Pak Generator | Legend Repositioning MOD | My GitHub | My Site

User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: problem in checking login status

Post by emosbat » Sat Jul 27, 2013 9:56 am

it is defined in main website script (www.domain.com) and not froum. I posted part of script that I use to check phpbb login. I turned off error reporting because I got notice error for main website script but no special error received from phpbb when I turn it on ;) problem is that current code do not return username. I am not sure it is becuase that forum is in different subdomain or not.

User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: problem in checking login status

Post by emosbat » Sat Jul 27, 2013 10:12 am

ok, I just moved that part of script to forum path for testing:

Code: Select all

// phpBB inclusion protection
define('IN_PHPBB', true);
define('DEBUG', false);
define('DEBUG_EXTRA', false);
//error_reporting(0);

$phpbb_root_path = '/home/xxx/domains/forum.xxxx/public_html/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if ($user->data['user_id'] == ANONYMOUS) {
	$phpbblogin=FALSE;
} else {
	$phpbblogin=$user->data['username_clean'];
}

echo $phpbblogin;
and its return correct username. so it is because different subdomain? how can I fix it?

User avatar
Tom
Former Team Member
Posts: 2665
Joined: Tue Jun 20, 2006 2:12 am
Name: Tom Catullo
Contact:

Re: problem in checking login status

Post by Tom » Sat Jul 27, 2013 10:14 am

I have to apologize — I seem to have been so concerned about the FORUM_PATH constant being defined that I neglected to consider the important fact that your forum and main website reside at different domains. My mistake. :)

Unfortunately, you cannot check for phpBB sessions on a different domain than the one at which your forum resides. The forum.domain.com cookie domain is correct for your forum, since it is located at forum.domain.com, but this means that checking for your forum's session information on any other domain, such as domain.com, will not be possible due to the differing cookie domains. The cookie domain and the domain at which you're checking for the user session need to be the same for phpBB sessions to be recognized.
Tom Catullo - Former Moderator Team Member
phpBB3 Smiley Pak Generator | Legend Repositioning MOD | My GitHub | My Site

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25228
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: problem in checking login status

Post by Paul » Sat Jul 27, 2013 11:14 am

Set you cookie domain to .domain.com (Note the first dot) and it should work fine.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: problem in checking login status

Post by emosbat » Sat Jul 27, 2013 11:16 am

Paul wrote:Set you cookie domain to .domain.com (Note the first dot) and it should work fine.
yep it works thanks! :)

note: could clear browser cache to work or change cookie prefix name in phpbb.

Locked

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