[PHP] Using $PATH_INFO as variables (inspired by www.DevShed.com)

2002-01-30 Thread Dr.Bob

Hi,
I'm trying to figure out how www.devshed.com does what I want to achieve
also, this is my point:

my main URL (for example) is www.mycompany.com
I want the central page about our projects to be found under
www.mycompany.com/projects
and project LovePeaceAndBananas under
www.mycompany.com/projects/LovePeaceAndBananas

I already know that this can be achieved by using the $PATH_INFO as
variables, to be used in de main file in the root of the site.
So far I have my Apache webserver accept files with no extention (index, in
stead of index.php) to be parsed as PHP. But if I look at the site of
DevShed, I don't see them using a file at all! I can't get it to work on my
local test system to make an URL like
www.mycompany.com/projects/LovePeaceAndBananas without the existens of a
file called 'projects'.
Can anyone tell me their 'trick'? (unfortunately, they don't show their page
source anymore like they used to do ...)

Also, when I try to extract the variabeles from the $PATH_INFO I get some
errors depending whether or not I end with a slash, and I do want to make
this fool prove, so that when a site visitor deletes the slash at the end,
it doesn't result in an error.

This is the code I made:

---
?php
$var_array = explode(/,$PATH_INFO);
$words = array_unique ($var_array);
$total = count($words);
for ($i = 0; $i = $total; $i++) {
echo variable  . $i .  =  . $var_array[$i].br;
}
?

---


And when I call this file (localhost/index) like this:
http://localhost/index/one/two/three/

This is my output:

---
variable 0 =
variable 1 = one
variable 2 = two
variable 3 = three
variable 4 =

---

Ofcourse I don't need the variable 0 and 4, can someone tell me where they
come from?
And, as said above, I get an Undefined Ofset-warning when I don't have a
closing slash at the end, how can I protect this?

Phew -- a lotta lotta questions here, hope someone can help me to climb this
PHP-mountain:-)
Thanx in advance!
Dr.Bob







RE: [PHP] Using $PATH_INFO as variables (inspired by www.DevShed.com)

2002-01-30 Thread Matt Williams



m:

 my main URL (for example) is www.mycompany.com
 I want the central page about our projects to be found under
 www.mycompany.com/projects
 and project LovePeaceAndBananas under
 www.mycompany.com/projects/LovePeaceAndBananas

 I already know that this can be achieved by using the $PATH_INFO as
 variables, to be used in de main file in the root of the site.
 So far I have my Apache webserver accept files with no extention
 (index, in
 stead of index.php) to be parsed as PHP. But if I look at the site of
 DevShed, I don't see them using a file at all! I can't get it to
 work on my
 local test system to make an URL like
 www.mycompany.com/projects/LovePeaceAndBananas without the existens of a
 file called 'projects'.
 Can anyone tell me their 'trick'? (unfortunately, they don't show
 their page
 source anymore like they used to do ...)


Hi

see this page for more details

http://www.phpbuilder.com/columns/tim19990117.php3

You do actually need the file called projects. This is the file that does
all the work.

It didn't quite work exactly as that for me, so here's what I did just in
case you need it.

add the follwoing into  .htaccess under you site root

## set rewrite rule for author
RewriteRule ^/projects/(.*) /projects?rest_of_url=/$1

Then add this to your projects file

$_MY_PATH = explode(/,$PATH_INFO);
array_shift($_MY_PATH);

This will give you the array of elements that come after projects.
i.e /projects/LovePeaceAndBananas/one

$_MY_PATH[0] // this will be LovePeaceAndBananas
$_MY_PATH[1] // this is one

etc

HTH

m:


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]