Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok, have to use an html form to log into a directory protcted by a simple htaccess file. This is not the best way to handle this you say? I know. I made the following login script:
[b]login.php[/b]Code: Select all
<?php
header('Location: http://' . $_REQUEST['username'] . ':' . $_REQUEST['password'] . '@' . 'domain.com/secure_dir/');
?>P.S. I know that there are plenty of scripts available to print headers that tell the browser to display a login window, but this is not what I want. I just want the script to do it based on values submitted in the html form. Thanks in advance.
solution: I actually spent over an hour googling this the other day, but today I found the solution in about ten minutes, go figure. This will work in IE if you do it with javascript instead of php. Like this:
in header of login.html
Code: Select all
<script type="text/javascript">
function Login() {
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var server = document.getElementById('server').value;
if (username && password && server) {
var htsite = "http://" + username + ":" + password + "@" + server;
window.location = htsite;
}
else
{
alert("Please enter your username and password.");
}
return false;
}
</script>
Code: Select all
<form name="login" onsubmit="return Login();">
<input type="hidden" id="server" name="server" value="domain.com/protected_dir/index.htm">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td nowrap class="captions">User Name </td>
<td class="captions"> <input name="username" type="text" id="username" size="20"></td>
</tr>
<tr>
<td class="captions">Password </td>
<td class="captions"><input name="password" type="password" id="password" size="20"></td>
</tr>
<tr>
<td class="captions"> </td>
<td class="captions"><input type="submit" name="Submit" value="Go"></td>
</tr>
</table>
</form>
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]