Login Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Login Form

Post by christh »

Hi

Can somebody help with the mechanics/thought process behind a login form? I can do all the form creation and user checking but I'm struggling with performing the validation on the same page as the form and then moving to a new page once all is good - apologies should this not make sense but I'm struggling to explain it even to myself. The code below may help.

Code: Select all

if(isset($_POST['submit'])) 
{ 
1.Connect and check the input against the records stored.
2.If everything is good, return to the page that called for the login
3. If it's not good return to the form
}

}

?>

<HTML>
<title><title>Login</title></HEAD>
<BODY>
<FORM method="post" action="<?php echo $PHP_SELF;?>">
	<label for ="login" >Login</label>
   	<input type="text" name="login" style="font-size:10px;" value="your email address">
	<label for ="password" >Password</label>
	<input type="password" name="password" style="font-size:10px;">
<input type="submit" name="submit" value="Login">
</FORM>
If I use the PHP_Self reference, how do I then move away from the form once everything is ok? Or if I set the from action to go to the page I want to ultimately go to how to I validate the information before going and stay if it's wrong?

Again sorry for the confusing content above but I'm not sure how best to explain.

Thanks

Chris
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: Login Form

Post by JayBird »

Code: Select all

if(isset($_POST['submit'])) 
{ 
$data = $_POST;

if(!empty($data['emailAddress'] )&& !empty($data['password']))
}
header("Location: /path/to/your/next/page");
}

?>

<HTML>
<title><title>Login</title></HEAD>
<BODY>
<FORM method="post" action="<?php echo $PHP_SELF;?>">
	<label for ="login" >Login</label>
   	<input type="text" name="login" style="font-size:10px;" value="your email address" value="<?php echo $data['emailAddress']; ?>>
	<label for ="password" >Password</label>
	<input type="password" name="password" style="font-size:10px;" value="<?php echo $data['password']; ?>>
<input type="submit" name="submit" value="Login">
</FORM>
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: Login Form

Post by christh »

Jaybird

Many thanks for your help.

Didn't know about header("Location: /path/to/your/next/page"); which is really handy.

Thanks again.

Chris
Post Reply