Need help redirecting URL...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

surreylee
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Feb 10, 2014 5:08 pm

Need help redirecting URL...

Postby surreylee » Mon Feb 10, 2014 5:20 pm

I am trying to re-direct users to specific URLs depending on their input from another page. Code listed below:

<?php
$user1=999;
$user2=100;
$user3=200;

$account=$_POST["account"];

if ($account==$user1)
{
header ('Location: /support.html');
exit;
}
elseif ($account==$user2)
{

header('Location: /services.html');
exit;
}
elseif ($account==$user3)
{
header('Location: /about.html');
exit;
}
else
{
echo "this don't work";
}
?>

I have also tried ('Location: http://mydomain.com/about.html'); and to no avail.

User avatar
macek
php-forum Active User
php-forum Active User
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am
Contact:

Re: Need help redirecting URL...

Postby macek » Mon Feb 17, 2014 11:47 pm

What is the output of the script? "this don't work" or nothing ( blank page ) ?

pietercdevries
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 18, 2014 2:38 pm

Re: Need help redirecting URL...

Postby pietercdevries » Tue Feb 18, 2014 3:14 pm

Hi why don't you use "Case" instead of an "If" statement

BTW: I didn't test this code.

Code: Select all

<?php
$user1=999;
$user2=100;
$user3=200;

$account=$_POST['account'];

switch ($account) {
   case $user1:
       header("location: /support.html");
         break;
   case $user2:
       header("Location: /services.html");
         break;
   case $user3:
        header("Location: /about.html");
         break;
}
?>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests