Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Hit counter using txt file - On multiple pages
Old 06-10-2008, 04:06 PM Hit counter using txt file - On multiple pages
Super Talker

Posts: 129
Trades: 1
Hi,

I have been spending the last few days trying to work out hit counters. I am talking about the ones that are displayed on YouTube, under the videos. You know the one that says "Views : 222, 222"(for example).

I wanted to replicate this for my site. I want to show a video and under it, show how many views it has had.

There are many scripts available on the net but I'd rather try and make one myself as opposed to just using someone elses. This way I can further my understanding of PHP.

I know a little bit about PHP now, after reading up a LOT on the internet and W3SCHOOLS.

I have edited: No txt file is necessary. As mentioned by nyef, txt files are a bad idea for decent traffic websites, for that reason I am removing that idea.

Does anyone have any other solutions where I can show the views like YouTube does?

Thank you for your help.
__________________

Please login or register to view this content. Registration is FREE

Last edited by yourmediaking; 06-11-2008 at 02:08 AM..
yourmediaking is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2008, 10:32 PM Re: Hit counter using txt file - On multiple pages
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Using a text file for something as ubiquitous as a hit counter is a bad idea. File system access is much much slower than memory. If your website starts getting decent traffic, every single page load by every single user will be writing to disk.

Store the counter in your database, or even better in memory.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-11-2008, 02:05 AM Re: Hit counter - On multiple pages
Super Talker

Posts: 129
Trades: 1
Quote:
Originally Posted by nyef View Post
Using a text file for something as ubiquitous as a hit counter is a bad idea. File system access is much much slower than memory. If your website starts getting decent traffic, every single page load by every single user will be writing to disk.

Store the counter in your database, or even better in memory.
Can you explain?

Ok, I'll avoid the txt file. But, what's the alternative.
__________________

Please login or register to view this content. Registration is FREE
yourmediaking is offline
Reply With Quote
View Public Profile
 
Old 06-11-2008, 02:15 AM Re: Hit counter using txt file - On multiple pages
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Well if you have a mysql database you can create a table in there with 2 columns: page and hits, then just create as many as you want and each time you get a hit that you want recorded just:
PHP Code:
$page 'current_page.php';
$query="UPDATE `table_name` SET hits=hits+1 WHERE page=$page";
$result=mysql_query($query); 
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-11-2008, 05:49 PM Re: Hit counter using txt file - On multiple pages
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Delete!
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels

Last edited by shivaji; 06-11-2008 at 05:52 PM.. Reason: I didn't read full first post before submit. After I see mistake.
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Reply     « Reply to Hit counter using txt file - On multiple pages
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17948 seconds with 12 queries