Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    UK
    Posts
    90
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Help with redirecting a page using if and else possibly

    Hi,
    I've been trying to redirect to 2 different pages based on a variable within the url.

    Basically

    if $site=site1 redirect to this page with the following parameters
    if $site=site2 redirect to this page with the following parameters

    i've tried every tutorial and even tried the switch, but with no luck.

    Please could somebody show what i'm doing wrong

    Heres the code
    Thanks in-advance
    Jenna


    Code:
    <?php
    $site=$_GET['site'];
    
    if($site == 'site1') {
          
    $host  = $_SERVER['HTTP_HOST'];
    $extra = 'downloadsite1.php?';
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $unencodedP = urldecode(stripslashes($_REQUEST['p']));
    $costP = ($_REQUEST['c']);
    $userP = ($_REQUEST['u']);
    $networkP = ($_REQUEST['n']);
    $regionP = ($_REQUEST['r']);
    header("Location: http://$host$uri/$extra$unencodedP&n=$networkP&u=$userP&r=$regionP&c=$costP");
    
    }
    
    if($site == 'site2') {
    
    $host  = $_SERVER['HTTP_HOST'];
    $extra = 'downloadsite2.php?';
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $unencodedP = urldecode(stripslashes($_REQUEST['p']));
    $costP = ($_REQUEST['c']);
    $userP = ($_REQUEST['u']);
    $networkP = ($_REQUEST['n']);
    $regionP = ($_REQUEST['r']);
    header("Location: http://$host$uri/$extra$unencodedP&n=$networkP&u=$userP&r=$regionP&c=$costP");
    
    }
    
    exit;
    ?>

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You explained what you want, but you didn't explain what problem you're having.
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    Oct 2009
    Location
    UK
    Posts
    90
    Thanks
    14
    Thanked 0 Times in 0 Posts
    The Problem i am having is that it is not re-directing to the correct page if site=site1 or if site=site2,

    just get a blank page.
    Jenna

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    A blank page usually means there's a parse error or syntax error in the code and your error reporting is turned off, so you can't see it. Search the forum for "php error reporting" to learn how to turn it on. Then post your error.
    Are you a Help Vampire?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •