adiwood Posted March 31, 2006 Share Posted March 31, 2006 Hi, I have been trying to look at some of the session tutorials, although i always seem to get lost, since i dont know how to apply them to what i have. I have a login page, that the user fills in the username and password, a response page then validates the user, and redirects them to the correct page depending on their usertype - e.g username, admin, superadmin.Where do i have to put the different parts of the session so that users can access to the admin page by typing it in. Also, this code is rather long winded at the moment. How can i cut it down? I guess i need to do something with $blnHitError = true;Sorry, but im totally lost on this!! Below is my code:[code]<?php { $domain = "localhost"; $username = "root"; $password = "paxcroft"; $database = "traceability"; $connection = mysql_connect($domain, $username, $password); $database = mysql_select_db($database, $connection); $user = mysql_query("SELECT `Userid`,`UserType` ". "FROM `Users` ". "WHERE `UserName` = '".$_POST['username']."' ". "AND `Password` = '".$_POST['password']."' ". ";", $connection); $userRecord = mysql_fetch_array($user); $UserType = $userRecord["UserType"]; if ($userRecord["Userid"] > 0) { $CurrentUser = $userRecord["Userid"]; if (!$_POST['password'] = $userRecord["password"]) { if ($UserType == 'User') { session_register("$username","$password"); header( "Location: user.php" ); } elseif ($UserType == 'Admin') { session_register("$username","$password"); header( "Location: admin.php" ); } elseif ($UserType == 'SuperAdmin') { session_register("$username","$password"); header( "Location: superadmin.php" ); }; }; } else { ?> <html> <head> <title>Avon Technical Products Traceability System</title> <link rel=StyleSheet href="style.css" type="text/css"> </head> <body> <form action="response.php" method="POST"> <div id="wrapper"> <div id = "header"> <div id = "logo"> <img src="images/avon_logo.gif" alt="Avon Technical Products" title="Company logo" /> </div> <div id = "pageInfo">Avon Technical Products Traceability System</div> </div> <div id="subNav"> <li><A HREF="index.php"><div id="button">Try Again</div></a></li> </div> <div id = "content"> <div id = "mainContent"> <div id = "title">LogOn</div> <div id = "Information"> Sorry, unable to login. Please check your user name and password. </div> </div> </div> </div> </div> </form> </body> </html> <?php } mysql_close($connection);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6271-sessions-help/ Share on other sites More sharing options...
ober Posted March 31, 2006 Share Posted March 31, 2006 I don't understand why you have 2 else statements or why there is a semicolon after the closing bracket of the if/else statements. The semicolon is going to halt execution and not do the else regardless of what else you have.Also for sessions, just make sure you put session_start(); at the very top of the page (directly after the opening PHP tag and make sure there is no space or HTML before that.Then all you have to do is set your variables:[code]<?php$_SESSION['user'] = $_POST['username'];$_SESSION['pass'] = $_POST['password'];$_SESSION['leve'] = $_POST['level'];?>[/code]Then as long as you put session_start(); at the top of the rest of the pages you use, you should have access to those variables and you can show or hide different parts of your site depending on what level people are at. And if those variables aren't set, just redirect them to the login page. Quote Link to comment https://forums.phpfreaks.com/topic/6271-sessions-help/#findComment-22642 Share on other sites More sharing options...
adiwood Posted March 31, 2006 Author Share Posted March 31, 2006 Hi,Thank you for your reply. I have edited the code, and it still works, so that is sorted. Will looking into the sessions now. Thank you for your reply. Quote Link to comment https://forums.phpfreaks.com/topic/6271-sessions-help/#findComment-22651 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.