Forum Moderators: coopster

Message Too Old, No Replies

Sessions and logins

         

dave1236

7:56 pm on Aug 31, 2006 (gmt 0)

10+ Year Member



Yesterday (I think), I posted a message about how to provide access to my content without requiring logins (currently I check user status prior to loading each page, and if they are not logged in, I direct them to the login page.

However, I have realized this is overkill for my purposes. Basically, all I want is a my page to recognize if a user is signed in, present a kind word to them, and if not, tell them they are not signed in.

I use sessions to accomplish this. Here is some sample code of what I would like to accomplish:

If they have logged in, this shows up:

<?php
echo "<html>
<body>
Welcome Back $firstName $lastName";
?>

If not, then the message "You are not logged in!" will appear in the smae place instead, with a link to the login page.

I am sure this is relatively easy, but alas, I cannot seem to figure this out (as usual!)

Thanks for your advice!

henry0

12:06 pm on Sep 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use session_register [us3.php.net]

And do something in those lines:

session_start(); // to initiate sessions
if (session_is_registered("authentification"))
{
//carry on!
}
else {
header("Location:index.php?error=intru"); // redirection to a login GUI page
} //error_reporting(E_ALL); // use to check your error

//Error needs to be turned on in your PHP.ini for test purpose
//and off for production