Page 1 of 1

Using dirname to get a directory path...

Posted: Thu Feb 05, 2009 10:25 am
by oscardog
So instead of doing something like PAGE.php?blah=var (As google does not like that for obvious reasons) I want to do it like this:

Im going to embed a flash object in a page so the structure will look like 'http://DOMAIN.com/games/GAMENAME' so i want to get the 'GAMENAME' part and put it into a variable so what line of code would i use?

Thanks :)

Oscardog

Re: Using dirname to get a directory path...

Posted: Thu Feb 05, 2009 1:32 pm
by lancecoder
<?php
$urlArray = split("/",$_SERVER['PHP_SELF']);
$gameName = $urlArray[count($urlArray)-1];
?>

Lancecoder.

Re: Using dirname to get a directory path...

Posted: Thu Feb 05, 2009 5:27 pm
by RobertGonzalez
Don't use PHP_SELF. It can be manipulated and is not always available to you. If you are trying to snag that part of the URI then look at $_SERVER['REQUEST_URI']. If you are pathing that on your own server then consider realpath() as well as basename() and the constant __FILE__.