473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Most Viewed PHP Tutorial

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
5 1891
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
<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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: NotGiven | last post by:
I am guessing I would hold a variable of when it's opened, then in the script that runs when the page is offloaded, I coudl calcualte it. How do you store a time variable? How do you calculate...
4
by: la_haine | last post by:
I have a collection of pages that are designed to be called into an iframe (named displayView), and the managers don't want people to be able to view them unless they're in that iframe. If I use...
3
by: Damian | last post by:
Hi everyone I'm having an issue with one of our applications. I'm getting the following error when attempting to log in to the site: Server Error in 'xxxxxxxxxxxxxxxx' Application....
4
by: Tom | last post by:
I have a form with a tabControl with 6 tabPages. There are textBoxes on all the tabPages that are bound to a dataset. The user can click a modify button, edit whatever textBoxes they want and then...
4
by: piscogirl | last post by:
Hi all, Here's my case: I have a form: Event Form and a subform: AttendanceSubForm The user selects a name (from a Person Table) on the subform to register for the event. If the name is...
19
by: Viken Karaguesian | last post by:
Hello everyone, Just an observation here: the CSS newsgroup (comp.infosystems.www.authoring.stylesheets) is totally dead. Why?... Anyway here's my discussion point: What is the most versatile...
3
by: romcab | last post by:
Hi guys, I would like to ask any idea on how I can make this program. I don't know if javascript can do this but I just want to try. What i want is to create a program or add a code to an...
2
by: teneesh | last post by:
I have a report where the field ConfType is viewed grouped vertically in a ConfType Header. Now I need to change it so that it is viewed horizontally across the page. How the heck do i do this? I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.