Page 1 of 1

php code help with directing based on url

Posted: Sun Mar 28, 2010 8:09 am
by clcintx
Hey guys - I'm a coldfusion programmer and need to know how to do something in php - I need control the code that is processed based on the url. For example something like:

www.mydomain.com/a

run this code

www.mydomain.com/b

run some other code

www.mydomain.com/c

run the last bit of code

Re: php code help with directing based on url

Posted: Mon Mar 29, 2010 1:32 pm
by AbraCadaver
Several ways to go about it. The two that come to mind:

Code: Select all

switch(basename($_SERVER["REQUEST_URI"])) {
    case 'a':
    //do something
    break;

    case 'b':
    //do something else
    break;
}
Or if you use get parameters it might be easier:

http://www.mydomain.com?cmd=a, http://www.mydomain.com?cmd=b, http://www.mydomain.com?cmd=c, etc... Then use $_GET['cmd'] to determine what to do.