Page Tracking;
Moderator: General Moderators
Page Tracking;
I'm trying to build a script where the page a guest is viewing is captured in the db. I've seen this before where a page number is captured as opposed to the string file name. My question is do you do this with a db table or a switch function or some other means.... Why caputre a number as opposed to the string file name?
Thanks.....
Thanks.....
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Re: Page Tracking;
I'm not understanding this.neophyte wrote:My question is do you do this with a db table or a switch function or some other means....
neophyte wrote:Why caputre a number as opposed to the string file name?
- number is compact in storage requirements
- a file may have more than one page in it that you may want to track seperately
- multiple files may share the same "page"
- if you change the filename, you lose all previous counts for that page, now don't you?
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
This is what I'm talking about Feyd. I'm trying to do this. My site does have multple views on a single file. Do you have to hard code every instance like:Buddha443556 wrote:If you have a dynamic site where every page can be identified by an ID number then that might be all you need.
Code: Select all
$page = 1- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can do either hardcoding or calculation, it's up to you. If you're going to have a small number of pages, you can simply hardcode the number or fetch it from a secondary mapping table (filename/circumstances to page id), otherwise you can use the algorithm. I often use a little bit of both.. I hardcode a base page id (typically through the database), then I add to that specific amounts for the circumstances of the request to differenciate between pages within.
I think I see what you want to do... I'd do something like this, just to make it quick.
Entirely up to you how you want to do it, though. The above means you only need one line per page, and all your page numbers are in one spot.
On the other hand, you could simply store the filenames themselves in the database rather than ids.
This is assuming you don't have too many pages. If you have a few hundred.... heh.
Also, if you want to pages with variables as separate entries, you'll have to modify a bit. (/page1.php?view=1 different form /page1.php?view=2)
[offtopic] http://webgeneius.com/ << geneius. funny. ^^;
Code: Select all
//counter.php
$pages = array(
'/page1.php' => 1,
'/page2.php' => 2,
);
//query database something like...
mysql_query("UPDATE tb SET count=count+1 WHERE page='".$pages[$_SERVER['PHP_SELF']]."' LIMIT 1");Code: Select all
//page#.php
include 'counter.php';
//...On the other hand, you could simply store the filenames themselves in the database rather than ids.
This is assuming you don't have too many pages. If you have a few hundred.... heh.
Also, if you want to pages with variables as separate entries, you'll have to modify a bit. (/page1.php?view=1 different form /page1.php?view=2)
[offtopic] http://webgeneius.com/ << geneius. funny. ^^;
I think with this small site I'll hard code views. $page = 0; ect... inside of the various members.
Then I'll create a function where specific views are stored. Not specific pages.
Thanks. I'm plannng on making a "theme switcher" for the site. I like the transparency on your site Skara.
*edit note: I can't post today.... sorry.
Then I'll create a function where specific views are stored. Not specific pages.
Code: Select all
function get_view($page){
switch ($page){
case '1':
$view = 'homepage';
break;
case '2':
$view = 'post';
break;
}
return $view;
}[/quote]Skara wrote:
[offtopic] http://webgeneius.com/ << geneius. funny. ^^;
Thanks. I'm plannng on making a "theme switcher" for the site. I like the transparency on your site Skara.
*edit note: I can't post today.... sorry.
hm. I suppose that'll work well if you have multiple cases for one view, e.g.
but if it's one case per view, It would be much more effecient if you used an array.
Code: Select all
switch ($page) {
case 1:
case 2:
case 3:
$view = 'homepage';
break;
case 4:
//...
}Code: Select all
function get_view($page) {
$pages = array('homepage','post','next',...);
if ($page < count($pages)) return $pages[$page];
else return 'Undefined Page';
// e.g. if you have 10 elements and you pass 12 for $page, you won't get an error, per se.
}Nowhere close to finished with it, but thanks. ^_^I like the transparency on your site Skara.