Redirecting a page using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragon513
    New Member
    • Mar 2007
    • 1

    Redirecting a page using PHP

    Hi, I am a complete newbie. What I mean by is that... well.. I don't know nothing about PHP!

    And yet I am here... you must be wondering.

    I need a small program (script?) in php that can tell if URL contains the word index.php? and redirect the browsers according to the result.

    Any help will be greatly appreciated!
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    First, I feel I must ask. You know you need to have php installed on your server for it to work, right?

    If that's all good, and you want to create a program with php, all your code must be in .php files inside <?php ... ?> tags.

    With that knowledge, this code would send you to http://www.google.com if index.php? is in your url
    [PHP]
    <?php
    $URL = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
    if(strstr($URL, "index.php? "))
    {
    header("Locatio n: http://www.google.com" );
    }
    ?>

    [/PHP]

    Comment

    Working...