1 Replies - 1906 Views - Last Post: 19 April 2012 - 03:13 PM Rate Topic: -----

#1 Silent_Symon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 22-February 12

Display error message on login page

Posted 19 April 2012 - 09:53 AM

Hello again all, I am having a bit of trouble displaying errors to the user while they are attempting to login to my website, i've tried quite a few different methods and only one has displayed the error but then tries to display a whole page of contents when i don't want it too, I understand why it is doing this, I don't mind what language it's in, as long as it displays a message on the login page under the input poxes (which are in a div tag).

Here what I have so far...

.HTML
<div id = "div-Login">
<form action="login.php"  method="POST" target="loginerror">
<center><h2>Login Here</h2> <p>
	Username:  <input type="text" name="username"><p>
	Password:  <input type="password" name="password"><p>
	<input type="submit" name="submit" value="Login">
	</center>
	<a href="register.html"><pre>need to register? Click Here!</pre></a>
	</form>
	
<iframe name="loginerror" style="border: 0px; width: 200px; height: 100px; overflow: hidden;" src="login.php"></iframe>
	</div>



.PHP
if ($username==$dbusername&&$enc_password==$dbpassword) //if the username & encrpyted password matches the records in the database
	{
	if($admin !=0) //if the admin flag is true
		{		
			$_SESSION['level']='ADMIN';//admin is logging in
			header ("Location: admin.php"); //the user is an admin, direct to admin page
		}
else
	header ("Location: index.php"); //user is a customer, direct user to index page
	$_SESSION['username']=$dbusername; //set the session name to the database record username.
	}
else 
	//$nopass='TRUE'; 
	//header ("location: loginU.php"); 
	echo "Incorrect Password, Please try again"; // if incorrect password
}
else
	echo ("That username doesn't exist"); // if user doesn't exist
}
else
	echo ("Please enter a username and password"); //if either field is empty



Obviously, when the user sucessfully logs in the iframe is still trying to display the admin.php / index.php, i do not want this, but at the moment this is the only way I can get this simple message to display...

Any help will be welcome!

Is This A Good Question/Topic? 0
  • +

Replies To: Display error message on login page

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: Display error message on login page

Posted 19 April 2012 - 03:13 PM

One option is instead of echoing the message, pass a number which represents a particular message to your login script via $_GET. In your login script you'll then check to see if your $_GET value is set and display the appropriate message.

You also can implement a template system which is a lot simpler and cleaner.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1