Forums

PHP

This topic is locked

login and sessions

Posted 21 Nov 2006 03:10:04
1
has voted
21 Nov 2006 03:10:04 Alexis Lalas posted:
hello all.

i have already made my registration/login "system" for a website, but want to know how can i display a message or have the "login" link text changed once a member has logged. and also if they click the login link, to display a message saying youre already logged.

i suppose that has to be coded in the session variable, or something like that, right?


thanks

Replies

Replied 21 Nov 2006 07:28:40
21 Nov 2006 07:28:40 ASif Iqbal replied:
see what you need to do is to check the session variable . i m giving you one example..
when some submits his/her name and pass, save it to session like below i did for giving you and idea.

$user=$_POST[user];
$pass=$_POST[pass];
$sql="SELECT * FROM `customer` WHERE `user`='$user' and `pass`='$pass'";
$res=mysql_query($sql) or die("error id :-1".mysql_error());
$rows=mysql_num_rows($res);
if($rows)
{
$_SESSION[active_id]=$row[id];
$_SESSION[active_user]=$row[user];
header("location:index.php?msg=Welcome $user";
}

-------------------------------------------------------------------
now $_SESSION[active_id] and $_SESSION[active_user] containing the user name and id who is currently online.

now if someone clicks for login link first check these value like

if(isset($_SESSION[avtive_id]) && isset($_SESSION[avtive_user]))
{
header("location:index.php?msg=You are already logged in";
}
else
{
//redirect to login page.
}

----------------------------------------------------------------------------

code for change the link to login or logout

if(isset($_SESSION[avtive_id]) && isset($_SESSION[avtive_user]))
{
logout
}
else
{
login
}

Edited by - asif133 on 21 Nov 2006 07:30:16

Reply to this topic