I have a login form on my site but when members login they are returned back to the index page. I want them to go to the /members/index page.
How can this be done?
Here is what the code is I have.
<?php
if($_POST){
if($_POST['username'] == 'member750' && $_POST['password'] == '3access16'){
header("Location: members/index.html");
echo 'Login success';
}
else {
echo 'Login failure';
}
}
else {
echo '<form action="" method="post">';
echo 'Username: <input type="text" name="username" class="txtBox" value="-Enter your name-"/><br />';
echo 'Password: <input type="password" name="password" class="txtBox" value="-Your Password-"/><br />';
echo '<input type="submit" value="Login" />';
}
?>
Any help would be appreciated.
Are they returned back to the index page? From where? From the members/index page? Or is the header in this code never executed?
The login form is on the index page. So when they go to the form, I need them to be redirected to the /members/index.html page, but they are just being redirect back to the home page.
And I am very new to php, so I dont understand what you mean by is the header never being executed? Sorry for the dumb question, but you dont know unless you ask.
Don’t worry about dumb questions, ask everything. I’m going to ask some dumb questions too (because I don’t quite understand the situation) 
- In what page is the code you posted?
- Do you ever see that login form?
- What happens when you click on Login?
Ok, Let me try my best,.
I have the login form on the right of everypage that is not in the /members/ directory.
So I have like Index, Contact Us, About us… etc, etc, Which all have the same form on it.
When they put the username and pass in the login form and click Login, its like the site refreshes back to the index.html (or whatever page they were on when they logged in) but I want them to go directly to /members/index.html
I hope that made sense.
Ok, I understand. But the code that handles the form input is on the same page where the login form is. And in fact, the form sends the data to the current page (the form’s action attribute is empty). Now, if the username entered in the form is ‘member750’ and the password ‘3access16’, the user should be redirected to the members/index.html page. Otherwise, the message ‘Login failure’ should be shown instead of the login form.
Now, just for testing purposes, to see what parts of the script are actually executed, you might add some echo’s and/or print_r’s:
<?php
echo "$_POST contains : "; print_r($_POST); echo "<br />";
if($_POST){
echo "Inside the first IF<br />";
if($_POST['username'] == 'member750' && $_POST['password'] == '3access16'){
header("Location: members/index.html");
echo 'Login success';
}
else {
echo 'Login failure';
}
}
else {
echo '<form action="" method="post">';
echo 'Username: <input type="text" name="username" class="txtBox" value="-Enter your name-"/><br />';
echo 'Password: <input type="password" name="password" class="txtBox" value="-Your Password-"/><br />';
echo '<input type="submit" value="Login" />';
}
?>
What do you see?
Well for starters at the top of the login form I see this
Array contains : Array ( )
And it still doing the same thing, Refreshing to the index.php, and not to the /members/ area.