check if user is logged in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

check if user is logged in

Post by Infinity »

I'm running winXp pro
Fireserv Apache
Phpbb2 plus 1.3

Ive created the base of my website using the phpbb2 styles all the pages ive created are in fireserv/www/phbb2/mysite/
I want my web site to act as part of ez portal which is installed as part of phpbb2 plus so that I can access all the variables that phbb2 uses from my own pages i.e $username etc.
I want to be able to check if a user is logged in when they try to open my website pages

I think my problem is because my website is stored in phpbb2/mysite/ and not in the phpbb2 root if this is the problem is there a way around this
here is the code im using

Code: Select all

<?php 
define('IN_PHPBB', true);
$phpbb_root_path = './'; // relative directory path to your phpBB page 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// 
// End session management 
// 

if ($userdata['session_logged_in'])   
{
echo "you r logged in";

?>
<?php include("music_header.tpl") ?> 
<?php include("music_navbar.tpl") ?> 



<?php
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 
echo "<tr>";
echo "<td width='100%' background='../templates/fisubsilversh/images/cellpic3.gif'><div align='center' class='style2 style3'><strong>
          UK Number 1 Singles</strong></div></td>";
echo "</tr>";
echo "</table>";
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 


// set up field bar

echo "<td width='100%' background='../templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>display some text to tell users about this part of the site and maybe add some flash animation and music
hggjhghjgjgjgjgjjgbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb</div></td>";



// Finally we close off the table 
echo "</table>"; 

?>
<?php include("music_footer.tpl") ?>
<?php
}
 else              
{          
echo "You r not logged in"; 
} ?> 

?>
and i get this error
Warning: Failed opening './extension.inc' for inclusion (include_path='.;c:\php4\pear') in c:\fireserv\www\phpbb2\music_site\index.php on line 4

Warning: Failed opening './common.' for inclusion (include_path='.;c:\php4\pear') in c:\fireserv\www\phpbb2\music_site\index.php on line 5

Fatal error: Call to undefined function: session_pagestart() in c:\fireserv\www\phpbb2\music_site\index.php on line 10

I made a test page using

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './'; // relative directory path to your phpBB page 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// 
// End session management 
// 

if ($userdata['session_logged_in'])   
{
echo "you r logged in";
}
 else              
{          
echo "You r not logged in"; 
}
?>
and saved it in the phpbb2 root and it works fine
Last edited by Infinity on Thu Feb 05, 2004 1:47 pm, edited 1 time in total.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

a way of doing it that i use:

when the user logs in create a session variable with there username

on every page thereafter verify that the sessionvar is there or log them out
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

Post by Infinity »

users log on using ez portal which is part of phpbb2 plus so i'm assuming that the session is already created when they log on all the other parts of phpbb2 i.e forums etc. know if a user is logged on but ive added my own pages and these need to know if the user is logged in or not
I know nothing about how sessions work im a noob at php I use pieces of code stick them together and mess with them till they work (or not)
and hopefully learn a little on the way
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

when it comes to site and forum code integration im of little use
Post Reply