[SOLVED] Using $_SESSION[] variable
Posted: Mon May 26, 2008 6:37 am
Hi,
I'm trying to display a link to a certain page if a specific user is logged in but I can't seem to get it working.
I have done this in my LOGIN PAGE:
The _SESSION['logged_in'] = $lname; works nice on all pages but the following just does not want to work no matter what I try:
attempt 1:
attempt 2:
attempt 3:
One of two things happen, either the link is displayed throughout or it's not displayed at all. If search around for answers but couldn't find anything that relates to what I'm trying.
Help will be greatly appreciated.
I'm trying to display a link to a certain page if a specific user is logged in but I can't seem to get it working.
I have done this in my LOGIN PAGE:
Code: Select all
$query1="select uname,passwd from cks_users where uname = '$lname' and passwd = '$lpass'";
$result1=mysql_query($query1) or die ("Could not log in because". mysql_error());
$query2="select uname,passwd from login where uname = '$lname' and passwd = '$lpass'";
$result2=mysql_query($query2) or die ("Could not log in because". mysql_error());
$query1="select uname,passwd from cks_users where uname = '$lname' and passwd = '$lpass'";
$result1=mysql_query($query1) or die ("Could not log in because". mysql_error());
$query2="select uname,passwd from login where uname = '$lname' and passwd = '$lpass'";
$result2=mysql_query($query2) or die ("Could not log in because". mysql_error());
if (mysql_num_rows($result1) > 0) {
$_SESSION['basic_is_logged_in'] = true;
$_SESSION['logged_in'] = $lname;
$_SESSION['cks'] = true;
mysql_query("update cks_users set last_login=SYSDATE() where uname='$lname'") or die (mysql_error());
mysql_query("insert into user_audit(uname,user_action,date_time) values('$lname','LOGIN',SYSDATE())");
header('Location: cksmain.php');
} elseif (mysql_num_rows($result2) > 0) {
$_SESSION['basic_is_logged_in'] = true;
$_SESSION['logged_in'] = $lname;
mysql_query("update login set last_login=SYSDATE() where uname='$lname'") or die (mysql_error());
mysql_query("insert into user_audit(uname,user_action,date_time) values('$lname','LOGIN',SYSDATE())");
header('Location: main.php');
}
else {
echo "<center><h4><font color=\"red\">Incorrect Username or Password</font></h4></center>";
}
attempt 1:
Code: Select all
<?php if (!$_SESSION['cks']) {} else { echo "<a href=\"cksmain.php\">Back to CKS Main</a>"; } ?>Code: Select all
<?php if ($_SESSION['cks'] = true) { echo "<a href=\"cksmain.php\">Back to CKS Main</a>"; } ?>Code: Select all
<?php if ($_SESSION['cks'] = true) { echo "<a href=\"cksmain.php\">Back to CKS Main</a>"; } else {} ?>Help will be greatly appreciated.