با سلام
من یه اسکریپت از خود مجید آنلاین گرفتم که افراد آنلاین و بازدید امروز ودیروز رو نشون میده و خیلی خوب و ساده هستش! اما من بازدید ماهانه رو هم می خوام نشون بدم اگر کسی می تونه کمک کنه این قسمت رو هم برام بنویسه ممنون میشم! ببخشید ...
ممنون می دونم خیلی پروام ولی شرمنده...
من یه اسکریپت از خود مجید آنلاین گرفتم که افراد آنلاین و بازدید امروز ودیروز رو نشون میده و خیلی خوب و ساده هستش! اما من بازدید ماهانه رو هم می خوام نشون بدم اگر کسی می تونه کمک کنه این قسمت رو هم برام بنویسه ممنون میشم! ببخشید ...
کد:
<?php
/*****************************************************************
** **
** ___________________________________ **
** | | **
** | [SimonStenhouse.NET] Statistics | **
** |___________________________________| **
** **
** **
** --------------------------------------------------------- **
** **
** Author: Simon Stenhouse **
** Date: 22.11.2005 **
** Version: 1.1 **
** Website: http://www.simonstenhouse.net/ **
** License: http://www.gnu.org/licenses/gpl.txt **
** **
** --------------------------------------------------------- **
** **
** Requirements: **
** **
** - PHP 4 >= 4.3.0 or PHP 5 **
** **
** Features: **
** **
** - Easy Installation **
** - Flat file system (no database needed) **
** - Display visitor data as text or images **
** - Show the number of users currently online **
** - Show unique IP counts for Today, Yesterday and Total **
** - Optional email notification upon reaching milestones **
** **
** --------------------------------------------------------- **
** **
** Installation: **
** **
** 1 Open statistics.php and adjust the settings in the **
** configuration area as needed. **
** **
** 2 Upload statistics.php to your sites root directory. **
** **
** 3 Create a directory named 'data' off of the root **
** and then CHMOD 777 that directory. **
** **
** 4 Create a directory named 'images' off of the root **
** and then upload the included image files to it. **
** **
** --------------------------------------------------------- **
** **
** Resulting Structure: **
** **
** /statistics.php **
** /data/ **
** /images/0.gif **
** /images/1.gif **
** /images/2.gif **
** /images/3.gif **
** /images/4.gif **
** /images/5.gif **
** /images/6.gif **
** /images/7.gif **
** /images/8.gif **
** /images/9.gif **
** /images/dot.gif **
** /images/comma.gif **
** /images/online.gif **
** /images/today.gif **
** /images/yesterday.gif **
** /images/total.gif **
** /images/ip.gif **
** **
** --------------------------------------------------------- **
** **
** Usage example: **
** **
** Online: <?php echo $online; ?> **
** Today: <?php echo $today; ?> **
** Yesterday: <?php echo $yesterday; ?> **
** Total: <?php echo $total; ?> **
** **
** Online: <?php text_to_image($online); ?> **
** Today: <?php text_to_image($today); ?> **
** Yesterday: <?php text_to_image($yesterday); ?> **
** Total: <?php text_to_image($total); ?> **
** **
** See the included 'example.php' file for a more detailed **
** example. **
** **
** --------------------------------------------------------- **
** **
** History: **
** **
** 1.1 - 03.01.2006 **
** **
** Fixed: Visitor Count **
** **
** Visitor counts are tracked by IP addresses. IP's **
** visiting Today, that had also visited Yesterday, **
** had their Yesterday record updated to Today. This **
** was correct but their visit for Yesterday was then **
** lost and not included in the Yesterday count. **
** **
** To rectify this, the system for incrementating **
** counts has been changed so an IP can now have a **
** record for both Today and Yesterday. **
** **
** 1.0 - 22.11.2005 **
** **
** Full Release with all features present. **
** **
*****************************************************************/
/*****************************************************************
** **
** C O N F I G U R A T I O N **
** **
*****************************************************************/
// PATHS
// -----------------------------------------------------------------
// Root path of your site
$root = $_SERVER['DOCUMENT_ROOT'] . '/';
// Path to image files
$images = 'images/';
// Path to data files
// NOTE: This directory must have been CHMOD'd to 777
$data = 'data/';
// NUMBER FORMATTING
// -----------------------------------------------------------------
// Set to true if you want your numbers to be formatted with comma's (",") (true or false)
// EXAMPLE: If this is set to true, the number 10123 will be displayed as 10,123.
$use_number_format = true;
// EMAIL NOTIFICATION
// -----------------------------------------------------------------
// Set to true if you want to receive an email notification whenever your total visitor count reaches a milestone (true or false)
$notify = true;
// Your email
$email = "[email protected]";
// Your site address
$domain = "3FX.co.sr";
// Total visitor counts that are regarded as milestones
$milestones = array(1, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000, 25000, 50000, 75000, 100000, 250000, 500000, 750000, 1000000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000, 4500000, 5000000, 10000000);
/*****************************************************************
** **
** F U N C T I O N S **
** **
*****************************************************************/
// PURPOSE: Check whether a file exists. If it doesn't, the file is created.
// PARAMS: [string] $file - The full path and name of a file
// RETURN: [bool] True if file exists | False if file didn't exist but was created
function statistics_check_file($file)
{
if (!file_exists($file))
{
$handle = fopen($file, "w");
fclose($handle);
chmod($file, 0666);
return false;
}
return true;
}
// PURPOSE: Converts a number string to an image representation.
// PARAMS: [string] $number - A number, in the format of #### or #,###
// RETURN: [echo] XHTML image tags
function text_as_image($number)
{
global $images;
for ($i = 0; $i < strlen($number); $i++)
{
$digit = substr($number, $i, 1);
if ($digit == ".")
{
$digit = "dot";
}
elseif ($digit == ",")
{
$digit = "comma";
}
echo '<img src="' . $images . $digit . '.gif" alt="" />';
}
}
/*****************************************************************
** **
** I N I T I A L I S E V A R I A B L E S **
** **
*****************************************************************/
// DATA FILES
$file_detail = $root . $data . 'detail.dat';
$file_total = $root . $data . 'total.dat';
$file_notify = $root . $data . 'notify.dat';
// VARIABLES
$ip = $_SERVER['REMOTE_ADDR'];
$online = 0;
$today = 0;
$yesterday = 0;
$total = 0;
$minutes = 15;
$time = time();
$day = date("j");
$month = date("n");
$year = date("Y");
$detail = "";
$match = false;
$match_today = false;
$milestone_new = false;
/*****************************************************************
** **
** S C R I P T **
** **
*****************************************************************/
// If the detail file doesn't exist, it will be created
statistics_check_file($file_detail);
// Read data from detail file into an array
$detail = explode("\n", file_get_contents($file_detail));
// Open the detail file for modification
$handle_detail = fopen($file_detail, "w");
// Loop through the detail array
foreach ($detail as $line)
{
// Split and store array values
list($stored_ip, $stored_time, $stored_day, $stored_month, $stored_year) = explode("|", $line);
// Determine yesterday's correct date
$temp_day = $day - 1;
$temp_month = $month;
$temp_year = $year;
if ($temp_day == 0)
{
$temp_month--;
if ($temp_month == 0)
{
$temp_month = 12;
$temp_year--;
}
switch ($temp_month)
{
case 1: $temp_day = 31; break;
case 2: $temp_day = 28; break;
case 3: $temp_day = 31; break;
case 4: $temp_day = 30; break;
case 5: $temp_day = 31; break;
case 6: $temp_day = 30; break;
case 7: $temp_day = 31; break;
case 8: $temp_day = 31; break;
case 9: $temp_day = 30; break;
case 10: $temp_day = 31; break;
case 11: $temp_day = 30; break;
case 12: $temp_day = 31; break;
}
}
// If the users ip matches a stored ip...
if ($stored_ip == $ip)
{
$match = true;
// And the user is already visited today...
if ($stored_day == $day && $stored_month == $month && $stored_year == $year)
{
$match_today = true;
// Update time of visit
$stored_time = $time;
}
}
// If stored visit was today...
if ($stored_day == $day && $stored_month == $month && $stored_year == $year)
{
// Write back into detail file
fwrite($handle_detail, "$stored_ip|$stored_time|$stored_day|$stored_month|$stored_year\n");
// Increment the Today count
$today++;
// If the user was online within the last 15 minutes...
if ($time < $stored_time + ($minutes * 60))
{
// Increment the Online count
$online++;
}
}
// If stored visit was yesterday...
elseif ($stored_day == $temp_day && $stored_month == $temp_month && $stored_year == $temp_year)
{
// Write back into detail file
fwrite($handle_detail, "$stored_ip|$stored_time|$stored_day|$stored_month|$stored_year\n");
// Increment the Yesterday count
$yesterday++;
}
}
// If the user is not recorded as having visited OR if the user is recorded as having visited yesterday but not today...
if (!$match || $match && !$match_today)
{
// Write todays visit into detail file
fwrite($handle_detail, "$ip|$time|$day|$month|$year\n");
// Increment the Online, Today, and Total count
$online++;
$today++;
$total++;
}
// Close the detail file
fclose ($handle_detail);
// If the total file doesn't exist, it will be created and the default value of 0 will be written into it
if (!statistics_check_file($file_total))
{
$handle_total = fopen($file_total, "w");
flock($handle_total, LOCK_EX);
fwrite($handle_total, "0");
fclose($handle_total);
}
// Read data from total file
$total += file_get_contents($file_total);
// Update the total file
$handle_total = fopen($file_total, "w");
flock($handle_total, LOCK_EX);
fwrite($handle_total, $total);
fclose($handle_total);
// If the notify file doesn't exist, it will be created and the default value of 0 will be written into it
if (!statistics_check_file($file_notify))
{
$handle_notify = fopen($file_notify, "w");
flock($handle_notify, LOCK_EX);
fwrite($handle_notify, "0");
fclose($handle_notify);
}
// Read data from notify file (the last milestone reached)
$milestone_last = file_get_contents($file_notify);
// Open the notify file for modification
$handle_notify = fopen($file_notify, "w");
flock($handle_notify, LOCK_EX);
// Loop through the milestones array
foreach ($milestones as $milestone)
{
// If total count is a milestone, and this milestone hasn't already been reached,...
if ($total == $milestone && $milestone_last < $total)
{
// Write latest milestone into notify file
fwrite($handle_notify, $total);
$milestone_new = true;
break;
}
}
// If a new milestone was not recorded, write the old milestone back into the notify file
if (!$milestone_new)
{
fwrite($handle_notify, $milestone_last);
}
// Close the notify file
fclose($handle_notify);
// If email notification is turned on and a new milestone was reached, email the user
if ($notify && $milestone_new)
{
$mail_date = date ("d F Y");
$mail_time = date ("g:i A");
$mail_subject = "[ $domain ] Statistics - $total";
$mail_to = "$email";
$mail_message = "SITE: $domain\nDATE: $mail_date, $mail_time\nMILESTONE: $total\n";
$mail_headers = "From: $mail_subject <$mail_to>\n";
$mail_sent = mail($mail_to, $mail_subject, $mail_message, $mail_headers);
}
// If number formatting is turned on, apply the formatting
if ($use_number_format)
{
$online = number_format($online);
$today = number_format($today);
$yesterday = number_format($yesterday);
$total = number_format($total);
}
?>
ممنون می دونم خیلی پروام ولی شرمنده...