Hey guys
This PHP tutorial shall cover a BASIC authentication script enabling authorised users access to a specific website. This is my first tutorial for pixel2life.com and in this tutorial I will show on how to setup a login for your website using PHP.
Let's Start

<html>
<head>
</head>
<body>
<form action='index.php' method='post'>
Username: <input type='text' name='user'><br />
Password: <input type='password' name='pass'><br />
<input type='submit' value='Login'>
</form>
OK so here is our basic html from. In this we use the POST method and what are trying to do is to sent the value in USER and PASS to be authenticated by the script and to grand access or not. OK let's continue with the PHP coding.

<html>
<head>
</head>
<body>
<form action='index.php' method='post'>
Username: <input type='text' name='user'><br />
Password: <input type='password' name='pass'><br />
<input type='submit' value='Login'>
</form>
<?php
// lets start with PHP coding
// this variable is anyting you enter in username and the same thing with the password
$user=$_POST['user'];
$pass=$_POST['pass'];
// ok now let's start authenticate username and password
if (($user=="afg89") && ($pass=="php")) echo " Access Granted !";
else echo " Access Denied!";
// lets close php
?>
</body>
</html>
OK the script above authenticate and authorize user that have the correct pass and username. If it is wrong it will not let them in. Of course you can combine the with MySQL to more advanced login. And you can customize this script by redirecting to a page and if it's wrong it will redirect to a error page. Ok that's it , i hope you have learned anything and if you have any question PM me.
Pages (1) 1
Date Added: 25-12-2008
Votes: 2
Rating: 8
Views: 72
Author: afg89
Main Category:
PHP Coding
Sub-Category:
General Development
Rate:
Votes: 2
Rating: 8
Views: 72
Author: afg89
Main Category:
PHP Coding
Sub-Category:
General Development
Rate: