FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


htaccess Password Protection





thaonguyenxanh
htaccess Password Protection
Learn how to super protect your files without the use of mySQL.


Sponsors - Templates
This tutorial will help you learn how to password protect your file quickly and easily in a few lines of code.

The code can be split up into three if-else statements. Let's take a look at what we will have to do in order to set up the password protection:
If the user has not been authenticated, then use the PHP header and ask for a username and password.
Else, if the user's name is "spoono" and the password is "spoono", log in. Inside here you would put all the code for the user.
Else tell them the user/password failed.
Finally, here is the PHP Code:
[code]
<?
//part 1
if (!isset($PHP_AUTH_USER))
{
header("WWW-Authenticate: Basic realm=\"Spoono Password.\"");
Header("HTTP/1. 401 Unauthorized");
exit;
}

//part 2
else if(($PHP_AUTH_USER=="spoono") && ($PHP_AUTH_PW=="spoono"))
{
echo "You got in...";
//place the code for the whole user page in here
//you can also set up a redirect to the user page if you want
}

//part 3
else
{
echo "<html><body bgcolor=ffffcc>Faiiiiiiiil";
//fail try again
}
?>
[\code]
Some notes about this script: it is essential to note that this username and password will last the whole session, that means that as long as that explorer window is open, the name and password will be saved for that realm. So if you mistyped the name or the password, you'll have to close the explorer window and re-open it and try again. Not too tough was it? Well thats it folks. I hope it works out for you and if it doesn't, email for help at puccavn@walla.com and we'll try to help you out. :blink:
Guest
@thaonguyenxanh
htaccess Password Protection
Learn how to super protect your files without the use of mySQL.


Sponsors - Templates
This tutorial will help you learn how to password protect your file quickly and easily in a few lines of code.

The code can be split up into three if-else statements. Let's take a look at what we will have to do in order to set up the password protection:
If the user has not been authenticated, then use the PHP header and ask for a username and password.
Else, if the user's name is "spoono" and the password is "spoono", log in. Inside here you would put all the code for the user.
Else tell them the user/password failed.
Finally, here is the PHP Code:
[code]
<?
//part 1
if (!isset($PHP_AUTH_USER))
{
header("WWW-Authenticate: Basic realm=\"Spoono Password.\"");
Header("HTTP/1. 401 Unauthorized");
exit;
}

//part 2
else if(($PHP_AUTH_USER=="spoono") && ($PHP_AUTH_PW=="spoono"))
{
echo "You got in...";
//place the code for the whole user page in here
//you can also set up a redirect to the user page if you want
}

//part 3
else
{
echo "<html><body bgcolor=ffffcc>Faiiiiiiiil";
//fail try again
}
?>
[\code]
Some notes about this script: it is essential to note that this username and password will last the whole session, that means that as long as that explorer window is open, the name and password will be saved for that realm. So if you mistyped the name or the password, you'll have to close the explorer window and re-open it and try again. Not too tough was it? Well thats it folks. I hope it works out for you and if it doesn't, email for help at puccavn@walla.com and we'll try to help you out. :blink:

==================

nice idea .... but what name I should use to put those script ? is it "index.php"

... but it would be better if we use cookie or session Very Happy
n0obie4life
first, learn how to use the code function properly.
second, since when is there a NEED to modify files to use .htaccess
gaspar
Tht's very cool
But i don't understand a word!
dionet
ok, but where i put the file?
foggy
dionet wrote:
ok, but where i put the file?
Where ever you want. This is the file you want to protect with a password.

Notice where it says
Code:
echo "You got in...";
//place the code for the whole user page in here
//you can also set up a redirect to the user page if you want

That is what you would replace with the code for the page you don't want people to see.
Related topics
password coding help
Login without server scripting
htaccess
looking for password gate script
Password Protecting a webpage
Password Protection
Simple membership system needed
Need help with htaccess
Como funciona o .htaccess
How do i password protect a web page using html
Making a password protect page in dreamweaver
md5() Password Protection
General .htaccess tutorial.
Image linking within my site seems to not be working
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.