Creating a unique ID for every page in a site.

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Creating a unique ID for every page in a site.

Post 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?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

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

Post by jayshields »

What is your definition of "page"?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

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

Post 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.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

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

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post 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' )
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

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

Post 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...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

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

Post by daedalus__ »

encode the url as base36?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

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

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