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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.