[thelist] Re: PHP and / instead of ?

Carl J Meyer cjmeyer at npcc.net
Thu Jan 16 22:03:01 CST 2003


Hi Timothy,

On Thu, 2003-01-16 at 18:16, Timothy J. Luoma wrote:
> Ok, well I read that, and I don't understand it.... it seems much more
> complicated than what I need

Yes, the evolt article digs into Apache server techniques for getting
rid of the .php extension of your PHP file that are really unnecessary
for the basic technique.  Actually it's pretty simple.  Where you now
have:

/path/to/this.php?var=value

You can instead use

/path/to/this.php/var/value

And then in this.php, instead of accessing $_REQUEST['var'] to get
'value', you have to do slightly more processing.  $_SERVER['PATH_INFO']
will contain '/var/value', and you use explode() to extract the data.
Here's how:

// strip the initial slash
$pathInfo = ltrim($_SERVER['PATH_INFO'], '/');
// explode the string into an array
$pathBits = explode('/', $pathInfo);
// now $pathBits[0] = 'var' and $pathBits[1] = 'value'

Of course the technique works with more than two items, you can string
out that path as long as you need it.

explode() is actually a very simple function - it just splits a string
up into an array, chopping the string wherever it finds the specified
delimiter.  So explode('/', 'one/two/three') will return a three-element
array containing the values ('one', 'two', 'three').

I only know for sure that this works with PHP/Apache - maybe someone who
does PHP/IIS can tell us if that works as well?

HTH

Carl




More information about the thelist mailing list