View Single Post
Old 04-09-2003, 09:14 AM   #1 (permalink)
prendo
Registered User
 
prendo's Avatar
 
Join Date: Jun 2002
Location: Leeds
Posts: 11
prendo is on a distinguished road
How to check if a member is logged in?

Hi, I've created a member login section to my site and everything works fine except I can't figure out how to check if a user is logged in every time they visit a members only page.

I tried creating an include file called session_checker.php which defines a function called, you guessed it, session_checker.

Here's the code:

<?php //this function checks if user is logged in on a particular page
function session_checker(){
if(!session_is_registered('first_name')){
include 'login_form.html';
exit();
}
}
?>

Then on my members only page I started a session at the top and also tried to call the session_checker function via the include but this doesn't work for some reason. Here's the code:

<?php
session_start();
include 'session_checker.php';
session_checker();
?>


When I try to access the members only page I get the following error message:

Fatal error: Call to undefined function: session_checker() in /homepages/43/d70797741/htdocs/phpscripts/userlogin1.4/membersonly.php on line 3


So I'm obviously doing something wrong with my function. Can anyone see anything obviously wrong that I'm missing here??

Thanks
prendo is offline   Reply With Quote