Letterbomb05 Posted May 24, 2008 Share Posted May 24, 2008 Hey there, After fixing up my Login Script, I *HAD* got it working ok, although I have an error somewhere, and I'm not sure where, I hope someone here can help me fix it. I've had too many errors this week >_>. here are my 2 files, the problem is in 1 of them: MENU.PHP (included into the main page): <div class="indentmenu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="info.php">Info</a></li> <li><a href="mypage.php">My Page</a></li> <li><a href="www.team-recoil.com/forums">Forums</a></li> <li><a href="registerpage.php">Register</a></li> </ul> <br style="clear: left" /> <?php if(isset($_SESSION['registered']) || isset($_SESSION['member']) || isset($_SESSION['moderator']) || isset($_SESSION['admin'])){ ?> <ul> <li>You are logged in</li> </ul> <?php }else{ ?> <!--login form appearing at top of page if user isn't logged in--> <form method="post" name="login" action="login.php"> <ul> <li id="loginform">Username: <input id="username" type="text" name="username" /> Password: <input id="password" type="password" name="password" /></li> <li> <input type="image" value="Submit" src="login.gif" height="18px" style="padding-top:2px;" /> </li> </ul> </form> <?php } ?> </div> Login.php: <?php //database info $dbhost = "localhost"; $dbname = ""; $dbuser = ""; $dbpass = ""; //connect to db mysql_connect($dbhost, $dbuser, $dbpass)or die("Could not connect:".mysql_error()); mysql_select_db($dbname)or die(mysql_error()); //make sure data was entered in the fields if($_POST['username']!='' && $_POST['password']!='') { //set field data vars $username = htmlentities(mysql_real_escape_string($_POST['username'])); $password = md5($_POST['password']); //query db $query = "SELECT userid, username, rank FROM users WHERE username='".$username."' AND password='".$password."'"; $result = mysql_query($query) or die(mysql_error()); //check to see if there is a db match, if so do the following if(mysql_num_rows($result) === 1) { //set different sessions for different ranks $row = mysql_fetch_assoc($result); if($row['rank'] == 1) { //set the session and redirect user $_SESSION['registered'] = TRUE; include('info.php'); }else{ //tell the user the account isn't activated if their rank is 0 echo "Your account is not activated"; } }else{ //tell the user that they have entered an invalid username or password if this be the case echo "Invalid username or password"; } }else{ //if they havn't entered anything in the login form, tell them echo "No username/password entered"; } //end script ?> I also need login.php to set a different session for each rank; 1 = $_SESSION['registered'] 2 = $_SESSION['member'] 3 = $_SESSION['moderator'] 4 = $_SESSION['admin'] Anyway, my main problem right now is that when I login, the menu just shows me the Login form, as if no session has been set, it was working earlier, I'm not sure what's gone wrong :S Quote Link to comment Share on other sites More sharing options...
bilis_money Posted May 24, 2008 Share Posted May 24, 2008 Why are these blank? //database info $dbhost = "localhost"; $dbname = ""; $dbuser = ""; $dbpass = ""; Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 cause I'm not giving my db info to everyone Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 24, 2008 Share Posted May 24, 2008 can you explain what's wrong? what's the error? what's not happening that should? What's happening that shouldn't? Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 Edited the post to specify the problem Quote Link to comment Share on other sites More sharing options...
bilis_money Posted May 24, 2008 Share Posted May 24, 2008 I think it is helpful if you post the error message here, so it is easy for us to spot it. Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 Anyway, my main problem right now is that when I login, the menu just shows me the Login form, as if no session has been set, it was working earlier, I'm not sure what's gone wrong :S Quote Link to comment Share on other sites More sharing options...
bilis_money Posted May 24, 2008 Share Posted May 24, 2008 Did you assigned session_start();? Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 Nevermind, got that bit working, but still need some suggestions for how to create multiple sessions depending on the rank, all suggestions are appreciated! Quote Link to comment Share on other sites More sharing options...
jscix Posted May 24, 2008 Share Posted May 24, 2008 Your problem is either: a.) a session value is not getting assigned, you are forgetting to start_session. b.) $row = mysql_fetch_assoc($result); if($row['rank'] == 1) { //set the session and redirect user $_SESSION['registered'] = TRUE; include('info.php'); }else{ //tell the user the account isn't activated if their rank is 0 echo "Your account is not activated"; } This code right here is not being satisfied correct. Eg: Your db value for 'rank' is not set, or not '1'. Thus when, if(isset($_SESSION['registered']) || isset($_SESSION['member']) || isset($_SESSION['moderator']) || isset($_SESSION['admin'])){ Is executed, it is going to return false and return the login form. hope that helps. Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 Yes thanks, could you give some advice on how to start different sessions for different ranks? Quote Link to comment Share on other sites More sharing options...
bilis_money Posted May 24, 2008 Share Posted May 24, 2008 you learn a lot from this tutorial. http://evolt.org/node/60384 it has user level and remember me feature. and yes it's OOP... GOOD LUCK. Quote Link to comment Share on other sites More sharing options...
jscix Posted May 24, 2008 Share Posted May 24, 2008 Switch ($row['rank']) { case '1': $_SESSION['registered']; break; case '2': $_SESSION['member']; break; default: // throw error break } etc Quote Link to comment Share on other sites More sharing options...
Letterbomb05 Posted May 24, 2008 Author Share Posted May 24, 2008 Thanks everyone 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.