I feel that i have the solution in front of me and I can't find what i am doing wrong. I will write the code that i have developed untill now and i would be very gretfull if somebody could help me.
loginform.php. In this page the user is prompt to write the username and password in order to login.
PHP Code:
<? session_start(); if(session_is_registered('username')){ echo $username.". You have logged on!"; require("logoffheader.php"); }else{ ?> <form action="password_input.php" method="POST" name = "login"> <table align="center" bgcolor="#FFCC66"> <tr> <td align="center" colspan="2">Log On</td> </tr> <tr> <td>Username:</td> <td><input type="text" name="uname"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="passwd"></td> </tr> <tr> <td></td> <td><input type="submit" value="Log in" name="submit"><input type="reset" value="Reset" name="reset"></td> </tr> </table> </form> <? }?>
When the user click the submit button is redirected to the page
"password_input" which is performing the validation of the user:
PHP Code:
<? include "dbconnect.php"; if(empty($_POST['uname'])||empty($_POST['passwd'])){ header("Location: http://www.domain.com/Staff/loginform.php"); }else{ $uname= $_POST['uname']; $query = "SELECT * FROM Webusers WHERE username='$uname'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $encrypted_password = md5($_POST['passwd']); if($encrypted_password!=$row[password]){ echo "<h3>Your password is not correct. Please log on again!</h3>"; require("loginform.php"); }else{ session_start(); session_register('username'); $username= $uname; //this part has been added as neroux suggested
$SESSION['isAdmin']=$row[admin]=='yes'; header("Location:http://www.domain.com/Staff/check_login.php"); } } ?>
When the user has been verified and enter the website will display a navigation menu called "logoffheader.php". I want when the user is admin to display the menu called "logoffheaderAdmin.php" otherwise to display the "logoffheader.php". The following code i have written in order to display the menu "check_login".
PHP Code:
session_start(); if(session_is_registered('username')){ echo "Welcome ".$username."!". "Logon time is: ".Date("m/d/Y"); require($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php');
}else{ header("Location:http://www.domain.com/Staff/loginform.php");
}
Using all the above code it doesn't work .I tryied to write the following code and is working but only for the first page:
PHP Code:
<? session_start(); if(session_is_registered('username')){ echo "Welcome ".$username."!". "Logon time is: ".Date("m/d/Y");
$queryAdmin="select admin from Webusers where username='$username'"; $rsAdmin=mysql_query($queryAdmin); $rowAdmin=mysql_result($rsAdmin,'admin');
if ($rowAdmin=='yes'){ require("logoffheaderAdmin.php"); } else{ require("logoffheader.php");}
} else{ header("Location:http://www.domain.com/Staff/loginform.php"); }
?>
I am really sorry about this big coding but i don't know where i am doing wrong.So i will appreciate any help.
Thank you in advance,
Xenia
|