Jump to content

How to set username/password authentication for webpage


vinoth.thy

Recommended Posts

HI

JUst i am trying to assign authentication for my web page by using the code

 

<?php

if ($PHP_AUTH_USER != “XXX” or $PHP_AUTH_PW != “XXX”):

  header("WWW-Authenticate: " .

        "Basic realm=\"Protected Page: " .

        "Enter your username and password " .

        "for access.\"");

header("HTTP/1.0 401 Unauthorized");

?>

  <HTML>

<HEAD><TITLE>Authorization Failed</TITLE></HEAD>

<BODY>

<H1>Authorization Failed</H1>

<P>Without a valid username and password,

    access to this page cannot be granted.

    Please click ‘reload’ and enter a

    username and password when prompted.

</P>

</BODY>

</HTML>

<?php

else :

header("Location:http://localhost/");

endif;

?>

By using this code it always ask me the username and password just i entered the correct details since it ask me for authentication. Any body tell me how to use it.

<?php
if ($PHP_AUTH_USER != “XXX” or $PHP_AUTH_PW != “XXX”)
{
  header("WWW-Authenticate: " .
        "Basic realm=\"Protected Page: " .
        "Enter your username and password " .
        "for access.\"");
header("HTTP/1.0 401 Unauthorized");
?>
  <HTML>
<HEAD><TITLE>Authorization Failed</TITLE></HEAD>
<BODY>
<H1>Authorization Failed</H1>
<P>Without a valid username and password,
    access to this page cannot be granted.
    Please click ‘reload’ and enter a
    username and password when prompted.
</P>
</BODY>
</HTML>
<? }
else {
header("Location:http://localhost/");
}
?>

 

try this hope it works

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.