Page 1 of 1

Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 4:22 am
by onion2k
I have a need to be able to reference every page in my site using a unique ID. It's so I can attach meta data to pretty much anything. I'm considering using the name of the model that the page uses with the necessary _GET and _POST values stored in a string. There's no security implications so I'm not intending to hash the value or anything.

I did consider just using the URL itself, but the problem with that is that pages could potentially have redirects pointing to them, so two ids could end up referencing the same page. That would be a problem.

How would you do it? Is there a better/cleverer/more obvious solution?

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 7:12 am
by jayshields
What is your definition of "page"?

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 8:32 am
by onion2k
jayshields wrote:What is your definition of "page"?
Essentially any unique page that a user can see. So domain.php/index.php?content=1 is different to domain.php/index.php?content=2, and they're both different to domain.php/index.php?contactus which is in turn different to domain.php/index.php?user_id=wombats. Everything that needs an id goes through a single controller, so the actual script name isn't very useful, but the model+some other vars (from GET mostly, but occasionally POST, COOKIE, and SESSION) is pretty much all there is to work from.

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 9:48 am
by pickle
I was going to suggest URLs, but you've already thought of that. I don't need an explanation of why redirects would cause a problem, but I'm surprised they do. In anything I use a redirect for, it's almost always because the user is looking at an old url & I want to point them in the right direction. In those instances, I'd want the ID of the page their supposed to be viewing, not the one they requested. Plus, after a redirection, isn't that a new page load?

If you want the id of the first page they requested in the current "conversation", the only thing I can think of is sticking with the URL idea, set that as the ID in $_SESSION for the first page load, then destroy that session variable after the page is loaded. A redirection then, wouldn't destroy that session variable & you could reference it from whatever page users were redirected to.

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 10:16 am
by jayshields
It depends how your site is set up. I suppose if it's set up to use views in a certain way then each view would be a "page". I don't know how you could relate a page to a model as you've said.

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 09, 2009 3:18 pm
by allspiritseve
I'm guessing you have more than one type of content that could be a "page", so you can't add a foreign key from your meta data to a "page" table. You could go the other way around though, and give each unique meta data row an id. This can be referenced for any type of content you might think of as a "page"-- a good example might be adding meta data to each individual blog post, so you can cater keywords to that specific post.

If that won't work for you, you might consider database-wide unique keys, which would contain an auto incrementing key, a table name, and the primary key for the row in that table you want to reference. I know there's a name for this, but I can't think of it off the top of my head.

Re: Creating a unique ID for every page in a site.

Posted: Fri Dec 11, 2009 5:37 pm
by josh
Are you using MVC? Does your request object have something like ->getParams()

???

Make an action controller plugin that asks for these paramters. Then each controller+action can "blacklist" paramaters that should be ignored (things like sorting & pagination maybe?), that way not neccessarily every distinct thing the user can see will be counted, instead each "logical page" would be.

So each action would ask the logger to record a "page" request for:
Array( 'module' => 'whatever', 'controller' => 'watever', 'action' => 'whatever', user_id => whatever, that_thing_id = whatever )
when maybe the user was really requesting
Array( 'module' => 'whatever', 'controller' => 'watever', 'action' => 'whatever', user_id => whatever, that_thing_id = whatever, 'page' => 5, 'sort' => 'desc' )

Re: Creating a unique ID for every page in a site.

Posted: Tue Dec 15, 2009 11:52 am
by alex.barylski
I`m missing something but why can you not rely on the permalink URI of every page request and possibly hash them...

Re: Creating a unique ID for every page in a site.

Posted: Tue Dec 15, 2009 1:20 pm
by Christopher
It seem like a hash of full URL (including params) would work, or even just a hash of the params string. That is what is unique.

Re: Creating a unique ID for every page in a site.

Posted: Tue Dec 15, 2009 11:07 pm
by josh
PCSpectra wrote:I`m missing something but why can you not rely on the permalink URI of every page request and possibly hash them...
That depends, for instance look at Magento or Google shopping, they have "list" as well as "grid" view for search results. Most people would consider that to be the same logical page even though it has a different URI.

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 16, 2009 12:57 am
by daedalus__
encode the url as base36?

Re: Creating a unique ID for every page in a site.

Posted: Wed Dec 16, 2009 5:33 am
by Benjamin
arborint wrote:It seem like a hash of full URL (including params) would work, or even just a hash of the params string. That is what is unique.
I agree. Even with redirects, there ought to be a point in the system where this can be captured (or generated) and md5'ed.