Jump to content

Simple if then login thing I am trying to make, need help.


pankirk

Recommended Posts

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!

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");
}
?>

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"){
                    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.