1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Caracas, Venezuela
    Rep Power
    I need to redirect to a specific PHP file depending on the content of a variable, for example, in case the variable $action has a 1 then go to page add.php3, 2 then redirect to page modify.php3, etc. How could I go about doing this? Thanks in advance
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Niagara Falls (On the wrong side of the gorge)
    Rep Power
    You can use the header("Location: url"); to redirect, as long as you do it before sending anything to the output stream (i.e. HTML or print/echo).

    If you only have a couple of possibilities for the redirect location I'd just use an if:

    if ($action==1)
    header("Location: add.php3");
    header ("Location: modify.php3");

    If you have a few to several pages you could use a switch/case construct.

    But, if you have several values for $action, I'd use an array. You could set the array up in an included file for ease of editing.

    // begin actionarray.php3

    Then in the main script (perhaps you want to check to see if $action is set first):

    if (isset($action))
    include ("actionarray.php3");
    header("Location: $url[$action]");
    //do something else

Similar Threads

  1. php script won't work inside "cgi-local" directory
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: April 26th, 2004, 10:50 PM
  2. How to see the Memory used by a PHP script?
    By Pardall in forum PHP Development
    Replies: 4
    Last Post: February 13th, 2004, 03:54 PM
  3. Change this PHP script to use NETPBM instead of GD
    By hknight in forum Project Help Wanted
    Replies: 1
    Last Post: February 10th, 2004, 11:46 AM
  4. Replies: 1
    Last Post: February 4th, 2004, 01:39 PM
  5. Executing PHP script using crontab with PHP module
    By crazyIvan in forum PHP Development
    Replies: 0
    Last Post: January 23rd, 2004, 08:27 AM

IMN logo majestic logo threadwatch logo seochat tools logo