parsing order of php url?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm new to php but having a lot of fun with it writing an e-commerce
store. I am puzzled by the fact that all of the following URLs open the
same web page


Only the right most ProductID number controls the page viewed. Is this
always the case in PHP5? If it is guaranteed to be the case than I can
use this to great advantage in tracking the sequence of pages that a
visiter had viewed.


Re: parsing order of php url?

Yes, the left to right evaluation order of GET variables is a
documented feature of PHP.

A more efficient method it seems, would be to concat the ids like so:


Re: parsing order of php url? wrote:
Quoted text here. Click to load it

It will be the case as long as the $_POST, $_GET and $_REQUEST superglobals
are defined as associative arrays, where the last key overwrites previous
ones when equally named.

On the other hand, I think it's not a good idea to base your solution on
this behaviour, because it may be subject to future changes.

A more reliable way of seeing on which pages your visitor has been is to use



Re: parsing order of php url?

Thanks for the reply. I thought that using sessions would probably be a
better solution. The only thing is I won't know how many pages they
have visited so i would have to either make a big array and hope it
does not overflow or I have to make a last in first out stack. but then
I'm worried if they use the back button I will not know where they are.
Any references or links on how to do this?


Re: parsing order of php url? wrote:
Quoted text here. Click to load it

Arrays in PHP do not have a pre-defined size, so you don't have to
worry about the size of the array, except if you use up available
memory. If a user uses the back button, you would not know where they
are using your scheme either. Also, as with any parameter passed via
the URL, your tracking can be faked.


Re: parsing order of php url?

Thanks, Ken. I'm used to C and allocating memory for arrays. So I can
use a session array to track the list of pages served to the visitor.
But what if they press the back button? How do I know to move back up
one in my array to display a horizontal list of links for how they got
to the category they are in? eg

You are viewing category:

Then they press back and then pick truck tires. I do not want the
horizontal list to say

becaue car tires was never removed from the array or I didn't know to
change a session variable called $currentListIndex from 3 to 2  (or 2
to 1 if arrays start with 0) when they pressed the back button. Make


Re: parsing order of php url? wrote:

Quoted text here. Click to load it

At each page, you could do something like:

When they hit the back button, I believe that some browsers will
actually add another entry into the array, so you might have something like:

.... 13, 45, 13 ...

Indicating that the user was on page 13, then clicked to 45, then hit
the back button. Watch out though, many people like to open multiple
windows (or tabs) when browsing, so that will give you some pretty awful

Justin Koivisto -

Re: parsing order of php url?

Ahh. Multiple browsers.

Perhaps I could write the series of categoryID used to get to the
current category directly in the web page. Somehow this would be
invisible to the user. Then when they click a new link their browser
sends me this series and I can append to it. This is a job for
javascript? And if they press the back button then the page they go
back to will have the correct series for that page. Sound good?

Re: parsing order of php url? wrote:

Quoted text here. Click to load it

If I am using some kind of breadcrumb, I tend to take the easy route:

Say I was viewing Truck tires (as in your previous example), my URI
would look like this:


Then for the breadcrumb, I'll just do something similar to:

        // in case there were two slashes together
        // in the URI, or if it ended with a slash.
        // **this will not add the top level link "/"
        // if URI started with a slash, then the first
        // element will be empty, leaving us with the
        // leading slash.
        $nav[]='<a href="'.join('/',$tmp).'/">'.
echo join(" &raquo; ",$nav);

Justin Koivisto -

Re: parsing order of php url?

Thanks Justin! I think i will do something like what you suggested
along with Chung Leong's post. I will explode a couple times to isolate
the concat CategoryID and then explode on the comma to get an array of
category ID's for something like the following link


Sound ok?

Is there an easier way to get the concat CategoryID ("21,22,23")
without having to explode cleverly a couple times incase some more text
follows in the url?

Thanks again,

Site Timeline