PHP MySQL Tutorial
Learn PHP and MySQL

User Authentication in PHP

60% of people found this useful
User Authentication in PHP

Here are some authentication method that we'll discuss

  1. Basic authentication
    We hard code the username and password combination in the login script itself. Suitable for simple application
  2. User & password stored in database
    A very common method. We store all the user name and password information in the database
  3. User authentication with image verification
    This is a more advance method of user authentication. We can prevent any automatic login by a robot ( script ) by using this method

All three of these methods will use the session. Since session is supported by PHP by default you don't need to configure anything to use it but you do need to use a recent version of PHP. By recent i mean greater than PHP 4.3.2. Using lesser than that version may cause the script to work only occassionally ( sometimes it won't work at all ). Don't ask me what cause that cause i don't about the reason too :-)

For the third method you will need GD library which is already bundled in PHP but you will need to enable the GD support before using the library.

To see if GD library is already enabled save the following code, execute it, and see what the result is

 

<?php
if (function_exists('imagecreate')) {
   echo "GD Library is enabled <br>\r\n<pre>";
   var_dump(gd_info());
   echo "</pre>";
} else {
   echo 'Sorry, you need to enable GD library first';
}
?>

If GD is not enabled yet open up php.ini and search for "extension=php_gd2.dll" ( without the quotes ). Uncomment the line by removing the semicolon ( ; ). After restarting your webserver try running the test script again. You should see the message saying that GD is enabled.

Recent Comments

By: Zack Fulpington Posted on 12-21-2008 6:21 PM

Linux instructions, please?

By: keremsah Posted on 03-02-2009 2:11 AM

yeah where is rest of codes buddy...

By: PHP Authentication Posted on 07-10-2009 1:04 PM

If you are interested in complete PHP Authentication module, check out www.phpauthentication.net

By: lornepare Posted on 07-16-2009 7:33 AM

Tutorial is incomplete.

Powered by Community Server (Non-Commercial Edition), by Telligent Systems