0

I need a simple login authentication for my beta site. This is what I found and I put it in my index.php (Joomla 2.5):

<?
//-- login
if ($_SERVER["PHP_AUTH_USER"] != "USERNAME" || $_SERVER["PHP_AUTH_PW"] != "PASSWORD")
{

    header("WWW-Authenticate: Basic realm=\"Enter username and password to proceed\"");  
    header("HTTP/1.0 401 Unauthorized");

    echo "<h1>Authentication failed</h1>";
}    
else
{
    echo "<h1>Authentication succeeded</h1>";
}
?>

The php login "pop-up" is showing perfect but when I click "cancel login" my website will be loaded anyway.

How can I prevent loading my website?

4

1 回答 1

2

You should have a die(); after the echo "<h1>Authentication failed</h1>"; to stop any more of the code being processed.

于 2013-02-19T22:53:49.740 回答