Content Top
DAL Computer Help » Web Development Help » Web Development Help » PHP Script Help » Need help with a simple code !

Recommended Fix

Click here to fix Windows Errors and Optimize Windows Performance

Need Computer Help?
Register Now for FREE

Need help with a simple code !

Reply
Thread Tools
PHP Script Help
  #1 (permalink)  
Old 21-01-2007, 07:22 PM
Junior Member
New Recruit
 
Join Date: May 2006
Posts: 48
vxdesigns Is a beginner here at D-A-L
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
  #2 (permalink)  
Old 21-01-2007, 09:47 PM
HappyBeaver's Avatar
Bea*ering Away!
Loyal Contributor
 
Join Date: May 2004
Posts: 517
HappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furnitureHappyBeaver is beginning to become part of the furniture
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
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
  #3 (permalink)  
Old 22-01-2007, 04:44 AM
Junior Member
New Recruit
 
Join Date: May 2006
Posts: 48
vxdesigns Is a beginner here at D-A-L
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
  #4 (permalink)  
Old 22-01-2007, 09:46 AM
D-A-L's Avatar
D-A-L Administrator
 
Join Date: Apr 2004
Posts: 3,534
D-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legendD-A-L is on their way to becoming a legend
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.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple question :) doondoon Windows Vista Help 1 17-03-2008 12:23 AM
This one is so simple and im so stupid!!!!! Sniper210010 General Hardware Issues 2 22-10-2006 10:26 PM
simple question mistajonz Windows XP Help 1 17-02-2006 07:27 AM
A real simple one hersnab A Question to the community! 4 04-05-2005 12:10 AM


All times are GMT +1. The time now is 05:07 AM.

Bottom Corner