By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Most Viewed PHP Tutorial

P: n/a
I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.

Does anyone here know of one?

Many thanks,

Alec
Aug 19 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Alec wrote:
I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.

Does anyone here know of one?

Many thanks,

Alec
You can either control the downloads yourself and increment a database
counter when a particular article, or you can parse your web server logs
to find out how many times a page has been accessed. Either works fine.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 19 '08 #2

P: n/a
<comp.lang.php>
<Alec>
<Tue, 19 Aug 2008 04:10:54 -0700 (PDT)>
<d1**********************************@v57g2000hse. googlegroups.com>
I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.
Millions of users have looked for avails on the internet and as far as i
know nobody has ever found one .

But what you could do is use a simple hidden hit counter to keep track
of how popular a news story is .

After that - its just a matter of how often you want to calculate and
sort the news storys into a top ten list - or whatever .
--
www.cannabisaware.co.uk
Aug 19 '08 #3

P: n/a
Jerry Stuckle wrote:
Alec wrote:
>I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.

Does anyone here know of one?

Many thanks,

Alec

You can either control the downloads yourself and increment a database
counter when a particular article, or you can parse your web server logs
to find out how many times a page has been accessed. Either works fine.
Just to add a bit to Jerry's remarks...

There's probably dozens of ways to do this. Although it is so easy
and ubiquitous to use a database, you can also just open a file and
either increment it or append a new line. The old hit counter trick was
to use a fake 1 pixel image:

<img src="path_to_hit_counter_script" height="1" width="1" alt="" />

That works for static pages as well. Since you are probably serving this
from a database, the database hit counter is probably the easiest to
implement. If you add a timestamp and insert each entry you can fake
your own easy to read server logs. Parsing the real server logs can be a
tough task for a relative newbie.

Google "PHP Hit Counter".

Jeff
>
Aug 19 '08 #4

P: n/a
Jeff wrote:
Jerry Stuckle wrote:
>Alec wrote:
>>I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.

Does anyone here know of one?

Many thanks,

Alec

You can either control the downloads yourself and increment a database
counter when a particular article, or you can parse your web server
logs to find out how many times a page has been accessed. Either
works fine.

Just to add a bit to Jerry's remarks...

There's probably dozens of ways to do this. Although it is so easy and
ubiquitous to use a database, you can also just open a file and either
increment it or append a new line. The old hit counter trick was to use
a fake 1 pixel image:

<img src="path_to_hit_counter_script" height="1" width="1" alt="" />

That works for static pages as well. Since you are probably serving this
from a database, the database hit counter is probably the easiest to
implement. If you add a timestamp and insert each entry you can fake
your own easy to read server logs. Parsing the real server logs can be a
tough task for a relative newbie.

Google "PHP Hit Counter".

Jeff
>>
You can, but you have to ensure you lock the file before opening it, and
unlock it after you close the file, to prevent multiple accesses (and
possible file corruption).

Databases are nice because they handle all of this for you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 20 '08 #5

P: n/a
Jerry Stuckle wrote:
Jeff wrote:
>Jerry Stuckle wrote:
>>Alec wrote:
I am starting the creation of a simple news website in PHP, and would
like to include a section for the 'most viewed' or 'most popular'
articles.

As a beginner to PHP, I have looked on google for such tutorials but
to no avail.

Does anyone here know of one?

Many thanks,

Alec
You can either control the downloads yourself and increment a
database counter when a particular article, or you can parse your web
server logs to find out how many times a page has been accessed.
Either works fine.

Just to add a bit to Jerry's remarks...

There's probably dozens of ways to do this. Although it is so easy
and ubiquitous to use a database, you can also just open a file and
either increment it or append a new line. The old hit counter trick
was to use a fake 1 pixel image:

<img src="path_to_hit_counter_script" height="1" width="1" alt="" />

That works for static pages as well. Since you are probably serving
this from a database, the database hit counter is probably the easiest
to implement. If you add a timestamp and insert each entry you can
fake your own easy to read server logs. Parsing the real server logs
can be a tough task for a relative newbie.

Google "PHP Hit Counter".

Jeff
>>>

You can, but you have to ensure you lock the file before opening it, and
unlock it after you close the file, to prevent multiple accesses (and
possible file corruption).
I was going to ask about that but I notice that php has flock. (Nice
that it has the same syntax) I suppose that doesn't work on windows.
>
Databases are nice because they handle all of this for you.
Agreed there!

Jeff
>
Aug 20 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.