pankirk Posted April 9, 2008 Share Posted April 9, 2008 I'm making a login for my site and using the same login form I want to let normal users and admins login. So I wrote this PHP script while($row = $result->fetch_assoc()){ if($row['username'] == "admin") { $isauth = "admin"; session_register('admin'); } if($row['username'] == $username) { $isauth = true; session_register('username'); } } if($isauth == "admin"){ header("Location:/page_edit.php"); } else { header("Location:/failed.php"); } if($isauth == "true") { header("Location:/user.php"); } (its only a part of the code) Anyway, if you look down at where im trying to do "if($row['username'] == "admin")" and then below it is another if statement for the normal users. Hopefully you can see what i'm trying to do because I cant seem to explain very well what i'm trying to do. Basically the if then statement part messes me up because when I login with the admin account it stil logs me in as a regular user. Same thing with the if then statements below it. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/100281-simple-if-then-login-thing-i-am-trying-to-make-need-help/ Share on other sites More sharing options...
discomatt Posted April 9, 2008 Share Posted April 9, 2008 Try a little debugging to isolate the problem <?php while($row = $result->fetch_assoc()){ echo '<p>Username:' . $row['username'] . '</p>'; if($row['username'] == "admin") { $isauth = "admin"; session_register('admin'); } if($row['username'] == $username) { $isauth = true; session_register('username'); } } echo '<p>$isauth = ' . $isauth . '</p>'; if($isauth == "admin"){ //header("Location:/page_edit.php"); } else { //header("Location:/failed.php"); } if($isauth == "true") { //header("Location:/user.php"); } ?> Also, if($isauth == "true") { header("Location:/user.php"); } Will never get executed. You probably want logic like this <?php if($isauth == "admin"){ header("Location:/page_edit.php"); } elseif($isauth == "true") { header("Location:/user.php"); } else { header("Location:/failed.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/100281-simple-if-then-login-thing-i-am-trying-to-make-need-help/#findComment-512753 Share on other sites More sharing options...
pankirk Posted April 9, 2008 Author Share Posted April 9, 2008 Thank you for your quick reply! Though it seems to still be giving me the error that when I login in the administrator account, it takes me to the admin page, but when I login as a normal user it still takes me to the admin page. So it looks like the normal users are getting the session_register('username'); AND the session_register('username');. I guess I just need help rewriting this part of the code because it's all jumbled up... i'm also wonerding if this type of if is possible. if($isauth == "admin" OR $isauth == "true"){ } Link to comment https://forums.phpfreaks.com/topic/100281-simple-if-then-login-thing-i-am-trying-to-make-need-help/#findComment-513168 Share on other sites More sharing options...
pankirk Posted April 9, 2008 Author Share Posted April 9, 2008 Ok I thought about it and I realise that I dont know whats going on anymore. My code looks great but why is it not doing what its supposed to do. I'm lost any help will be great please!. Link to comment https://forums.phpfreaks.com/topic/100281-simple-if-then-login-thing-i-am-trying-to-make-need-help/#findComment-513244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.