Content Top
DAL Computer Help » Web Design, Development & Marketing » Web Development Help » PHP Help » Need help with a simple code !

Need help with a simple code !


HEY! You're not logged in which is fine if you simply want to browse for answers, however if you want to post your own Questions and hangout here you need to Register! ...Registration takes 2 minutes and is completely free. If you have already registered simply log in using the form to the right.

Reply
Thread Tools
PHP Help
Old 21-01-2007, 07:22 PM   #1 (permalink)
Tech Rank 1/5
 
Status: Junior Member
Join Date: May 2006
Posts: 42
 vxdesigns Is a beginner here at D-A-L



vxdesigns is offline  
Cool Need help with a simple code !

Hey people how's life treating ya, i'm hoping everyone's having a good weekend.
I have a very simple PHP stats script which counts " Page hits, Unique hits, Todays Page hits, Todays unique hits" Here's the coding for it

Code:
<body>
<font face="Verdana" size="1">
<?php
// Our log file;
$counter = "stats.txt";

// Date logging;
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday . $month . $year;


// Log visit;
$fp = fopen($counter, "a");
$line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);

// Read log file into array;
$contents = file($counter);

// Total hits;
$total_hits = sizeof($contents);

// Total hosts;
$total_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
	$entry = explode("|", $contents[$i]);
	array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));

// Daily hits;
$daily_hits = array();
for ($i=0;$i<sizeof($contents);$i++) {
	$entry = explode("|", $contents[$i]);
	if ($current_date == chop($entry[1])) {
		array_push($daily_hits, $entry[0]);
	}
}
$daily_hits_size = sizeof($daily_hits);

// Daily hosts;
$daily_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
	$entry = explode("|", $contents[$i]);
	if ($current_date == chop($entry[1])) {
		array_push($daily_hosts, $entry[0]);
	}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));

?>
<? echo "
Page hits:<b> " . $total_hits . "</b><br><br>
Unique hits: <b> " . $total_hosts_size . "</b><br><br>
Todays Page hits: <b> " . $daily_hits_size . "</b><br><br>
Todays unique hits: <b>" . $daily_hosts_size; 
?>
It counts the page hits properly but it does not count the unique page hits properly meaning it doesn't count the unique page hits after the first unique hit although i;ve asked people in different areas with different ips to visit the page so i can be sure that something is wrong with the code.

Page hits: 10

Unique hits: 1

Todays Page hits: 10

Todays unique hits: 1

You see it keeps counting page hits but doesn't count uniques after the first one. I'm assuming somethings wrong with the coding, so please can someone take a look at the following coding and provide a fix ? I will greatly greatly appreciate it !


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Advertisement - Register to remove Ads its free!

Old 21-01-2007, 09:47 PM   #2 (permalink)
 
HappyBeaver's Avatar
 
Status: Bea*ering Away!
Join Date: May 2004
Posts: 501
 HappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L teamHappyBeaver is a key member in the D-A-L team

Send a message via ICQ to HappyBeaver Send a message via AIM to HappyBeaver Send a message via MSN to HappyBeaver Send a message via Yahoo to HappyBeaver


HappyBeaver is offline  
Re: Need help with a simple code !

I'm no expert but there is a difference in the code compared to the other entries...

Shouldn't it be

Code:
Todays unique hits: <b>" . $daily_hosts_size . "
instead of:

Quote:
Todays unique hits: <b>" . $daily_hosts_size;
__________________



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 22-01-2007, 04:44 AM   #3 (permalink)
Tech Rank 1/5
 
Status: Junior Member
Join Date: May 2006
Posts: 42
 vxdesigns Is a beginner here at D-A-L



vxdesigns is offline  
Re: Need help with a simple code !

Quote:
Originally Posted by HappyBeaver View Post
I'm no expert but there is a difference in the code compared to the other entries...

Shouldn't it be

Code:
Todays unique hits: <b>" . $daily_hosts_size . "
instead of:
No that gives an error :/


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 22-01-2007, 09:46 AM   #4 (permalink)
 
D-A-L's Avatar
 
Status: D-A-L Administrator
Join Date: Apr 2004
Posts: 3,081
 D-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furnitureD-A-L is beginning to become part of the furniture



D-A-L is offline  
Re: Need help with a simple code !

Quote:
Originally Posted by vxdesigns View Post
No that gives an error :/
You would still need a ";" at the end.
__________________
D-A-L

Please help support this Free Computer Help Service - Make A Donation


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PC restarts jephree PC Games 70 02-08-2006 08:53 AM
windows xp screen freezes Sarah Allen Windows XP Help 15 27-06-2006 12:49 AM
Bios/blue screen problem sweetagurl2000 Windows XP Help 3 17-05-2006 06:07 AM
Online Crash sharonuktang Windows XP Help 2 05-04-2006 10:24 PM
beep code list chou General Hardware Issues 2 29-11-2004 05:06 AM


All times are GMT +1. The time now is 03:19 AM.

Bottom Corner