Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Need help redirecting URL...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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.
surreylee
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Feb 10, 2014 5:08 pm

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 ) ?
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

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;
}
?>
pietercdevries
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Feb 18, 2014 2:38 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.