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

    Join Date
    Jan 2000
    Location
    Caracas, Venezuela
    Posts
    5
    Rep Power
    0
    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
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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");
    exit;
    }
    header ("Location: modify.php3");
    exit;

    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
    $url[1]="add.php3";
    $url[2]="modify.php3";
    $url[3]="whatever.php3";
    etc.

    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]");
    exit;
    }
    //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, 11: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, 04: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, 12:46 PM
  4. Replies: 1
    Last Post: February 4th, 2004, 02:39 PM
  5. Executing PHP script using crontab with PHP module
    By crazyIvan in forum PHP Development
    Replies: 0
    Last Post: January 23rd, 2004, 09:27 AM

IMN logo majestic logo threadwatch logo seochat tools logo