You are here: Re: keeping page count « All PHP « IT news, forums, messages
Re: keeping page count

Posted by Kentor on 10/13/06 15:49

mmmm interesting... this looks a bit more complex then I imagined... I
will try it out as soon as I get a chance. I thought I could simply
update the count of pageviews for each page but just compare the last
date and current date or something like that... thanks for your help,
ill try it asap

Steve wrote:
> "Kentor" <kentor@gmail.com> wrote in message
> news:1160750141.189599.130460@f16g2000cwb.googlegroups.com...
> | Hello,
> | I'm just trying to figure out the best way of keeping a page count for
> | each listing on my website...
> | I'd like to show how many page views each page has for a the present
> | day/week/month and since listed... and also keep a list of how many
> | times it has appeard in the results in total.. but maybe was not viewed
> | by the user... not sure how this can be done by using the minimul
> | amount of requests from db and the min amount of date checking and so
> | on... im also not sure whether i should store ips to check for
> | duplicate views or not... i guess not but... i just want some feedback
> | and some help if possible
> | thanks
>
>
> create a db table that stores the ip and stores the page and a date/time
> stamp. from there you could include a php footer file in each page. the
> included footer would do your tracking...
>
> ==========
>
> $ip = getenv(HTTP_X_FORWARDED_FOR)) ?
> getenv(HTTP_X_FORWARDED_FOR) :
> getenv(REMOTE_ADDR);
> $page = $_SERVER['PHP_SELF'];
> $sql = "
> INSERT INTO pageTracking
> (
> Page ,
> IpAddress ,
> Stamp
> )
> VALUES
> (
> '" . $page . "' ,
> '" . $ip . "' ,
> '" . date('Y-m-d H:i:s') . "'
> )
> ";
> db::execute($sql);
>
> from there, your reporting would be a simple select statement probably by
> page, date, and ip. one query would fit the bill for all of them (just by
> setting $breakOut to any field in the table):
>
> ==========
> <?
> $breakOut = isset($_REQUEST['breakOut']) ?
> $_REQUEST['breakOut'] :
> 'Page';
> $key = 0;
> $sql = "
> SELECT Page ,
> IpAddress ,
> Stamp
> FROM pageTracking
> ";
> $records = db::execute($sql);
> $report = array();
> foreach ($records as $record)
> {
> foreach ($record as $column => $columns)
> {
> if ($column == $breakOut){ continue; }
> $report[$breakOut][$key][$column] = $record[$column];
> }
> $key++;
> }
> $reOrdered = array_keys($records[0]);
> unset($reOrdered[$breakOut]);
> unset($records);
> unset($columns);
> $columns[] = $breakOut;
> $columns += $reOrdered;
> ?>
> <table>
> <th>
> <?
> echo implode("\n </th>\n <th>\n ", $columns);
> ?>
> </th>
> <th>
> Visits
> <tr>
> <?
> foreach ($report as $interest => $records)
> {
> foreach ($records as $record)
> {
> $visits = count(array_unique(array_keys($record[$interest])));
> foreach ($body as $column => $fields)
> {
> <?
> <td><?= $record[$column] ?></td>
> ?>
> }
> <?
> <td><?= $visits ?></td>
> ?>
> }
> }
> ?>
> </tr>
> <table>
>
> ==========
>
> keep in mind, this is simply generic output...i'd take the time to calculate
> visits for the grand total, then by each sub category. ex. Page (total),
> IpAddress (total visits for each page), Stamp (total visits on this day for
> this Ip for this page. NONE of that is hard, you simply need to reorganize
> your $records array used in the output so that the keys of the array are the
> field names of the table...then just get a count of the array_keys as shown
> above for $visits...just make sure you use the key of the data you'd like to
> add up. ex.
>
> ==========
>
> $records = db::execute($sql);
> $report = array();
> foreach ($records as $record)
> {
>
> $report['PAGE']['IPADDRESS']['STAMP'][$key] = $record;
> }
>
> ==========
>
> you'd adjust the code that followed in the example to match the change here.
> that gives you three different, detailed reports using one base of
> code...one physical report. this is great not only for marketing analysis of
> your site but a valueable security tool for monitoring site access.
>
> hth...i didn't test any of the code. it is from my memory of what i've done
> before. edit and syntax check as needed.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация