php code help with directing based on url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clcintx
Forum Newbie
Posts: 1
Joined: Sun Mar 28, 2010 7:52 am

php code help with directing based on url

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php code help with directing based on url

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply