Publishing System Settings Logout Login Register
Create a Simple Login in PHP
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on August 22nd, 2007
17910 views
PHP Coding
[MY_P2L_AD]

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.
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
AFG89

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top