tonyco Posted April 16, 2008 Share Posted April 16, 2008 hi there new to php and need help setting up a login page.I making a small program to check exam results and need to have to have two main pages one for the admin and one for students.The code is for the admin page and works ok I just need to add a second password function that allows students just to see View.php thanks Tony <? //start a session session_start(); //check if user is coming from a form if ($_POST[op] == "ds") { //check username and password if (($_POST[username] != "admin") || ($_POST[password] != "abc123")) { //handle bad login $msg = "<P><font color=\"#FF0000 \"><strong>Bad Login - Try Again</strong></font></P>"; $show_form = "yes"; } else { //handle good login $_SESSION[valid] = "yes"; $show_menu = "yes"; } } else { //determine what to show if ($_SESSION[valid] == "yes") { $show_menu = "yes"; } else { $show_form = "yes"; } } //build form block $form_block ="<h1>Login</h1> <form method=POST action=\"$_SERVER[php_SELF]\"> $msg <P><strong>username:</strong><br> <input type=\"text\" name=\"username\" size=15 maxlength=25></P> <P><strong>password:</strong><br> <input type=\"password\" name=\"password\" size=15 maxlength=25></P> <input type=\"hidden\" name=\"op\" value=\"ds\"> <P><input type=\"submit\" name=\"submit\" value=\"login\"></P> </FORM>"; //build menu block $menu_block ="<h1> </h1> <P><strong>Result Information</strong> <P><strong>Administration</strong> <ul> <li><a href=\"addres.php\">Add Results</a> <li><a href=\"modres.php\">Edit Results</a> <li><a href=\"delres.php\">Delete Results</a> <li><a href=\"viewres.php\">View Results</a> </ul>"; //assign the block to show to the $display_block variable if ($show_form == "yes") { $display_block = $form_block; } else if ($show_menu == "yes"){ $display_block = $menu_block; } ?> <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <? echo "$display_block"; ?> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted April 16, 2008 Share Posted April 16, 2008 It would be better to have a common login page but allow the users to select their category-students/teacher and so on and similarly forward the login to the respective pages(or to a single page and limit the access). Quote Link to comment Share on other sites More sharing options...
tonyco Posted April 16, 2008 Author Share Posted April 16, 2008 Hi Yeah Its just one log on page but need to allow two passwords the first goes to admin and works ok.What i need it do when the students log in is just to show the view view ,so would i just create another display box thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.