Using dirname to get a directory path...

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
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Using dirname to get a directory path...

Post 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
lancecoder
Forum Newbie
Posts: 2
Joined: Thu Feb 05, 2009 1:10 pm

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

Post by lancecoder »

<?php
$urlArray = split("/",$_SERVER['PHP_SELF']);
$gameName = $urlArray[count($urlArray)-1];
?>

Lancecoder.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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

Post 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__.
Post Reply