We help IT Professionals succeed at work.

php user redirect

mraconnor
mraconnor asked
on
485 Views
Last Modified: 2010-08-05
Very new to php and can't get this working can you please help.  


Once it is working i will use htacess to password the directory and another php form to add customer numbers to the redirect.php. this will allow a user to enter their client   numer into the form and be sent to their password protected directory.    I have looked at login scripts and can't find a simple one that will do what I want which is why I am going down this route.  

Many Thanks

Aaron


Hi this is the code for my html form:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="POST" action="redirect.php">
  Username: <input type="text" name="username" size="15" />
</form>
</body>
</html>
 
 
 
 
 
 
 
this is the code for the redirect.php
 
<?php
header('Location: http://www.finetechnologies.co.uk/'); 
// login page redirection 
 
if($user==="1777")
{ 
header('Location:1777page.php'); 
} 
elseif($user==="1558") 
{ 
header('Location:1558page.php'); 
} 
else
{ 
header('Location:loginpage.php'); 
} 
end if
?>

Open in new window

Comment
Watch Question

The example code for the redirect is as follows:
Please replace the code within <<>> with your own requirements.
The below is the login redirect.

if (<<CONDITION>>)
{
?>
<META HTTP-EQUIV="Refresh" Content= "0; URL=<?php
echo "/redirect.php?<<PARAMETER1>>=<A href=/login.php>Log In</A>&nbsp;>&nbsp;Error&message=Error in the query.Please make sure username and password are correct."; ?>">

<?PHP
}

Commented:
I am not sure what you are doing exactly. If you have the redirect header first it will never get to the if statement. I would try this:

<?php

$user = $_POST['username'];

if ($user=="1777"){
header('Location:1777page.php');
}
elseif($user=="1558") {
header('Location:1558page.php');
}
else {
header('Location:loginpage.php');
}
?>

You also do not have a submit button on your form.
the header() Tag can only be used if it is the first thing on the page.  If there is anything else (IE: HTML Code) then it will come up with an error.

Author

Commented:
rstewar:
I am not sure what you are doing exactly. If you have the redirect header first it will never get to the if statement. I would try this:

<?php

$user = $_POST['username'];

if ($user=="1777"){
header('Location:1777page.php');
}
elseif($user=="1558") {
header('Location:1558page.php');
}
else {
header('Location:loginpage.php');
}
?>

You also do not have a submit button on your form.





this did not work it just jumps to the loginpage no matter what you put in
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
rstewar:  what I am trying to achive is this.  

when a user wants to login to there own area on my site they will enter a there unique customer number into the form which will then be passed to the redirect.php then based on what they put they will be redirected to the right page.  

Author

Commented:
i have posted the code in full

Author

Commented:
2 parts to the code the form and the redirect.php

Commented:
Use this for redirect.php:
<?php
$user = $_POST['username'];
if ($user=="1777"){
header('Location:1777page.php');
}
elseif($user=="1558") {
header('Location:1558page.php');
}
else {
header('Location:loginpage.php');
}
?>

----------------------------------------------------------------------------

use this for the html form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="POST" action="redirect.php">
  Username: <input type="text" name="username" size="15" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Author

Commented:
This should be quite simple as all i am doing is if statment and redirecting to the header but it always goes to the loginpage no matter what i try

Commented:
The code I just posted works. I saved the form as login.php and entered 1777 for the username and hit submit. It redirects me to the correct page.

Author

Commented:
Hi  rstewar:

Many Many thanks works like a charm, not sure what I had done wrong but that worked thanks again have accepted your solution .  A+
This question should be closed with points assigned.

Author

Commented:
I assigned points to rstewar as it was his post that helped me the post you put was not any help
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.