PHP redirection page based on GET variables

只谈情不闲聊 提交于 2019-12-02 06:18:11

When comparing values in PHP for equality you can use either the == operator or the === operator. What’s the difference between the 2? Well, it’s quite simple. The == operator just checks to see if the left and right values are equal. But, the === operator (note the extra “=”) actually checks to see if the left and right values are equal, and also checks to see if they are of the same variable type (like whether they are both booleans, ints, etc.).

And

die(); you forget semicolon in die()

you code should be

if($_GET['id'] == 'youtube') {
    header('Location: http://www.youtube.com/') ;
    die();
}
if($_GET['id'] == 'twitter') {
    header('Location: http://www.twitter.com/') ;
    die();
}
if($_GET['id'] == 'reddit') {
    header('Location: http://www.reddit.com/') ;
    die();
}

You can try below code:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Please Wait...</title>
    </head>
    <body>

    <?php
    // directs the user to various locations on the internet
    extract($_REQUEST);

    if(isset($id) && $id == 'youtube') {
        header('Location: http://www.youtube.com/') ;
        die();
    }
    if(isset($id) && $id === 'twitter') {
        header('Location: http://www.twitter.com/') ;
        die();
    }
    if(isset($id) && $id === 'reddit') {
        header('Location: http://www.reddit.com/') ;
        die();
    }
    ?>

    </body>
    </html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!