i want to password protect a directory on my website using .htaccess but input the username and password from a form on my index page instead of the pop up box that apears when i try to access the protected directory, is this possible? prefrably i would like to use phpyou could try something like this in PHP. Use this HTML for the form:
<form action="parseform.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Log in">
</form>
and then this PHP script:
<?php
header("Location: <!-- m --><a class="postlink" href="http://">http://</a><!-- m -->" . $_POST["username"] . ":" . $_POST["password"] . "@www.your-server.com/protected_area/");
?>
Thanks for the reply!
I have set that up but i keep getting the error message:
Warning: Cannot add header information - headers already sent by (output started at /home/jward1/public_html/phplogin.php:2) in /home/jward1/public_html/phplogin.php on line 4
Sorry if this is just me missing something simple, im new to php eek:
Ben:the PHP code should be the only code in the entire .php file (or at least it should be the first code in it).heres a good place to learn how to password protect directories using .htaccess
<!-- m --><a class="postlink" href="http://www.google.co.uk/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=%2Ehtaccess+password+protecting+directories">http://www.google.co.uk/search?sourceid ... irectories</a><!-- m -->
there are many tutorials on how to accomplish itthere is no other code in the php file other than this:
<?php
header("Location: <!-- m --><a class="postlink" href="http://">http://</a><!-- m -->" . $_POST["username"] . ":" . $_POST["password"] . "@www.aplec.co.uk/admin/");
?>no spaces can be before or after <? ?>
and did you know that will not work for IE users. MS has disabled that so you cannot get hacked. if the user has been upgraded
and this won't work anyway. the user/pass that you enter in the popup login is variable set by the server, not php. so you need to login with the popup box.
<form action="parseform.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Log in">
</form>
and then this PHP script:
<?php
header("Location: <!-- m --><a class="postlink" href="http://">http://</a><!-- m -->" . $_POST["username"] . ":" . $_POST["password"] . "@www.your-server.com/protected_area/");
?>
Thanks for the reply!
I have set that up but i keep getting the error message:
Warning: Cannot add header information - headers already sent by (output started at /home/jward1/public_html/phplogin.php:2) in /home/jward1/public_html/phplogin.php on line 4
Sorry if this is just me missing something simple, im new to php eek:
Ben:the PHP code should be the only code in the entire .php file (or at least it should be the first code in it).heres a good place to learn how to password protect directories using .htaccess
<!-- m --><a class="postlink" href="http://www.google.co.uk/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=%2Ehtaccess+password+protecting+directories">http://www.google.co.uk/search?sourceid ... irectories</a><!-- m -->
there are many tutorials on how to accomplish itthere is no other code in the php file other than this:
<?php
header("Location: <!-- m --><a class="postlink" href="http://">http://</a><!-- m -->" . $_POST["username"] . ":" . $_POST["password"] . "@www.aplec.co.uk/admin/");
?>no spaces can be before or after <? ?>
and did you know that will not work for IE users. MS has disabled that so you cannot get hacked. if the user has been upgraded
and this won't work anyway. the user/pass that you enter in the popup login is variable set by the server, not php. so you need to login with the popup box.