PHP - Explain how to do user authentication in php.

Explain how to do user authentication in php.

The most convenient way to authenticate a user in PHP is to use session. Another way is to use HTTP authentication:-
<?php
if (!isset($_SERVER['PHP_AUTH_USER']))
{
     header('WWW-Authenticate: Basic realm="My Realm"');
     header('HTTP/1.0 401 Unauthorized');
     echo 'Text to send if user hits Cancel button';
     exit;
}
else
{
     echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
     echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

Explain how to do user authentication in php.

For user authentication, GD library is needed and is bundled with PHP. One needs to enable the GD support before utilizing the library.

To view the GD library, execute the following code.
<?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 disabled, then few changes need to be done in php.ini file. Find for extension=php_gd2.dll. Remove the semicolon to uncomment the script line. Restart the web server and run the test script. GD enabled message will be echoed. This confirmation message ensures the user authentication.
PHP - Explain how to set the browser timeout.
Explain how to set the browser timeout - Browser time out can be set using set_time_limit() method......
PHP - Explain how to create random passwords.
Explain how to create random passwords - Generating random passwords in PHP can be done in multiple ways depending on how much security the application demands...
PHP - Explain how to access a COM object from within my PHP page.
Explain how to access a COM object from within my PHP page - To access COM object from PHP page, COM class can be made use of.....
Post your comment