Log in

View Full Version : Execute code based upon URL



shehaal
09-16-2007, 11:04 AM
Hi there,

I would like to be able to execute a piece of code using PHP, based upon part of the URL. For example:


IF CurrentURL CONTAINS "/contact/" OR "/contact.php" THEN
DISPLAY HTML code
ELSE
DISPLAY HTML code

How would I go about inspecting the current location to see if it includes a particular path or file?

Thanks heaps,
Stuart.

Twey
09-16-2007, 11:12 AM
The URL after the current file is contained in $_SERVER['PATH_INFO']. E.G.:
if(starts_with($_SERVER['PATH_INFO'], '/user/register'))
if(@$_POST['action'] === 'register')
User::register_handler($_POST);
else
exit(User::register_form());The user could then go to /path/to/your/script.php/user/register and get the register page. Removing that annoying '.php' from the URL is simply a case of forcing the handler:
<FilesMatch "^yourscript$">
ForceType application/x-httpd-php
</FilesMatch>... and removing the .php extension from the bootstrap file.