Jump to content

[SOLVED] Uhh... I'm new to PHP an I need help with sessions...


gergy008

Recommended Posts

Heres a basic example

When i user logs in, you can set a session like this

<?php
session_start();
//connect to database and check login details
//get UserID eg $row['UserName']
//set to session
$_SESSION['UserName'] = $row['UserName'];
?>

 

Now on other pages if that session is set you can check it like this

<?php
session_start();
if(!empty($_SESSION['UserName']))
{
echo "Welcome Guest <a href=\"login.php\">Login</a>";
}else{
echo "Welcome ".$_SESSION['UserName'];
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.