Posts: 256
Location: Auckland, New Zealand
|
Lets give you something basic to work with, login pages really require some complexity to them, but if you're just starting out, how about just simple string comparisons. Everyone has to start somewhere, but simple checking whether one string is the same as the other is a basic login type system so here's some code:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> <title>Simple Login</title> </head> <body> <form id="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div> <label for="username">Username:</label> <input id="username" name="username" type="text" <?php if(isset($_POST['username']) && !empty($_POST['username'])) echo 'value="'.$_POST['username'].'" '; ?>/><br /> <label for="passwd">Password:</label> <input id="passwd" name="passwd" type="password" /><br /> <input id="submit" name="submit" type="submit" value="Login" /> </div> </form> <?php if(isset($_POST['submit']) && strcmp($_POST['submit'],'Login') == 0) { if(isset($_POST['username'],$_POST['passwd']) && !empty($_POST['username']) && !empty($_POST['passwd'])) { if(strcmp($_POST['username'], 'user1') == 0 && strcmp($_POST['passwd'], 'pass1') == 0) { echo '<p>Thank you for logging in ' . $_POST['username'] . '</p>'; } else { echo '<p>Sorry your login was incorrect, please try again.</p>'; } } else { echo '<p>You can not leave any fields blank.</p>'; } } ?>
</body> </html>
As long as this file is named with a .php extension, e.g. some_name.php and on your web server, it will work all from the same page.
There is no state remembering used in this, it's basically just asked you to insert your username which in this test is "user1" exact without quotes and case sensitive and the password is "pass1", which on successful login will display a confirmation, unsuccessful we ask you to try again, no input will tell you that you can't leave fields empty.
Since this is just a tiny example, it can still be used to move on to more complex things, only changes needed is in the code.
If you require any explanation in regards to this script, then please feel free to ask.
Cheers,
MC
__________________
#------------------------------ signature---------------------------------------------------------------------------------#
Quote:
|
I am well recognised for what I don't do than what I do. Chores are just one of those things.
|
Last edited by mastercomputers; 06-13-2006 at 08:14 AM..
|