1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Thread Options if accessing site from ?action=0 it will take to a different page from ?ac

Discussion in 'PHP & Perl' started by Josh-Emm, Sep 29, 2011.

  1. Josh-Emm

    Josh-Emm Registered Member

    Joined:
    Apr 12, 2011
    Messages:
    57
    Likes Received:
    9
    Ok to start of I know none PHP and i want people who access my site from the url http://WWW.EXAMPLE.COM/?action=0 to be taken to a different page from what you would if you accessed it from ?action=1 this is probs so easy but i have been searching for a day how to do it cant find anything :(
     
  2. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    PHP:
    <?php
    /**
     * if url parameter 'action' is set,
     * then decide where to redirect
     */
    if (isset($_GET['action'])) {
        if (
    $_GET['action'] == 1) {
            
    header("Location: http://www.url1.com/");
        } elseif (
    $_GET['action'] == 2) {
            
    header("Location: http://www.url2.com/");
        } elseif (
    $_GET['action'] == 3) {
            
    header("Location: http://www.url3.com/");
        } else {
            echo 
    "Action \"".$_GET['action']."\" was not found.";
        }
    } else {
        echo 
    "'Action' parameter is not set.";
    }
    ?>
     
  3. hustlehardx

    hustlehardx Newbie

    Joined:
    May 27, 2011
    Messages:
    19
    Likes Received:
    3
    ^that is one way, or simply a switch.
    PHP:
    <?php
    switch($_GET['id']){
        case 
    0:
    header("Location: website");
            break;
        case 
    1:
    header("Location: website");
            break;
        case 
    2:
    header("Location: website");
            break;
    default:
    header("Location: website");
    }
    ?>
    where default would be the page it will go to if there is none set.

    you would call it like id=1 etc etc.
    both will work, i've always used switches but to each their own