Thread: script.php?var

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

    Join Date
    May 2000
    Posts
    5
    Rep Power
    0
    How would i make PHP use something like file.php?variable to goto different spots in my script?..IE, i have an administration script im working on, and i want addusers, delete users, and a few other functions all in the same script so that i dont need 15 different script files, how would i do that?
  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 do it several ways. One way is to use an action variable and switch/case construct.

    script.php3?act=do_this

    where the argument (in this case "do_this") would tell the script what to do.

    <?
    switch ($act)
    {

    case 'do_this':
    some_function();
    break;

    case 'do_that':
    some_other_function();
    break;

    default:
    print "Hey, you didn't pass a valid argument!";
    exit;
    break;
    }
    ?>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    5
    Rep Power
    0
    kewl kewl, thanks alot, but umm, i know in perl there's like, querystrings, now..i know PHP has these, but i have yet to see anything dealing with them, is this more effeciant say for slow typers(coders) than the querystrings?..

    im new, and like what PHP has to offer, so dont mame me too bad please
  6. #4
  7. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Just use

    if($variable) {
    //do some code
    exit;
    }

    if($othervariable) {
    //do some other code
    exit;
    }

    etc...

    Thus the script will only run code for the variable that is set. Remember that the braces can encompass whatever you want to do, even if you escape out to html and then back into <?php script. The exit; statement prevents PHP from doing more than one code block at a time, but is not necessary, especially if you want to set two variables to run two code blocks.


    [This message has been edited by rycamor (edited May 16, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo