Logo

רד-בורד: ארכיון

ראשי > תיכנות > עזרה בPHP - מונה מבקרים

19/06/2006 22:37:42 Scorpion_Man
תראו קבלתי מונה מבקרים עכשיו יש לי איתו בעייה אני רוצה לעשות שכל 24 שעות המונה מתאפס אני לא מצליך מה הפקודה משהו יודע?
אני גם לא ממש מצאתי את המשתנה שאותו אני צריך לאפס כל 24 שעות בקיצור מי שמצליך אני ממש אודה לו
הקובצים :

counter.php:
<?
$num=1;
require "counter_conf.inc"; //loading the configuration file

$counter_visited=false; //determines if the page was visited or not
$counter_hitcount=$counter_initial; //initialize the counter with $counter_initial

/* sets/updates the cookie */
if ($counter_cookie_with) //if cookies are enabled
{
$counter_visited=isset($HTTP_COOKIE_VARS[$counter_cookie_name]); //checks if cookie exists
if ($counter_cookie_time==0) //if we want to save the cookie just for the window
setcookie($counter_cookie_name,"visited",0); //creates a cookie for this window only
else //if we set a period of cookie life time
setcookie($counter_cookie_name,"visited",time()+$counter_cookie_time); //creates/updates the cookie
}

/* reads/creates the hitcount file */
$counter_fp=NULL; //$fp holds handle to the counter file
if (!file_exists($counter_file)) //if the counter data file doesn’t exist
{
$counter_fp=@fopen($tcounter_file,"w+"); //creating the file for reading and writing
if (!$counter_fp)
;// echo "\n<B>ERROR: could not create the counter file.</B><BR>\n"; //echoing error message (disabled)
@fwrite($counter_fp,(string)$counter_initial); //writes the initial value to the file
@fclose($counter_fp); //closing the file
}
else
{
$counter_fp=@fopen($counter_file,"r"); //opening the counter file for reading
if (!$counter_fp) //if couldn’t open the file
;// echo "\n<B>ERROR: could not open the counter file.</B><BR>\n"; //echoing error message (disabled)
$counter_hitcount=(integer)@fread($counter_fp,filesize($counter_file)); //reads the hitcount from the file
if ($counter_hitcount<0) //if the hitcount is smaller or equal 0
$counter_hitcount=$counter_initial; //sets the hitcount to the initial value
@fclose($counter_fp); //closing the counter file
}

/* Prints the counter to the browser */
function CounterPrint($c=-1)
{
global $counter_hitcount,$counter_digit,$counter_zero_lead,$counter_length,$counter_image_width,$counter_image_height,$counter_font_family,$counter_font_color,$counter_font_size,$counter_style;
if ($c<0) //if we didn’t specify any positive counter to show
$c=$counter_hitcount;
$sc=(string)$c; //$sc is the string of $c
if ($counter_zero_lead) //if with leading zeros
$sc=str_pad($sc,$counter_length,"0",STR_PAD_LEFT); //pads the string with ’0’ to the left side
echo "<SPAN dir=\"ltr\">"; //the printing of the numbers goes from left to right. (important when combined with hebrew)
if ($counter_style=="image") //if the counter style is image
{
$img=getimagesize($counter_digit[0]); //gets the size of the image
$wid=($counter_image_width<0)?$img[0]:$counter_image_width; //sets the width
$hig=($counter_image_height<0)?$img[1]:$counter_image_height; //sets the height
for ($i=0;$i<$counter_length;$i++) //go over each digit from left to right
echo "<IMG src=\"".$counter_digit[$sc[$i]]."\" width=".$wid." height=".$hig." alt=\"".$sc[$i]."\">"; //echos the tag to show the image of the digit
}
else
//else if the counter style is text
echo "<FONT color=\"".$counter_font_color."\" font=\"".$counter_font_family."\" size=".$counter_font_size.">".$sc."</FONT>";
echo "</SPAN>";
}

/* Increases counter by $num. If num is negative we decrease the counter. (default=1) */
function CounterIncrease($num=1)
{
global $counter_file,$counter_hitcount,$counter_visited;
$counter_hitcount=55;
$counter_fp=@fopen($counter_file,"w"); //open the counter data file to writing. (overwrite the old data)
if (!$counter_fp) //if couldn’t open for writing
echo "\n<B>ERROR: could not open the counter data file for writing.</B><BR>\n";
$counter_hitcount+=$num; //increases the hit counter by 1
@fwrite($counter_fp,(string)$counter_hitcount); //writes the new counter hit to the file
@fclose($counter_fp); //closes the file
$counter_visited=true; //after updating the counter, the page was visited
}

/* Sets the counter to $c. if $c is -1, sets to initial number */
function CounterSetTo($c=-1)
{
global $counter_file,$counter_hitcount,$counter_initial;

$counter_fp=@fopen($counter_file,"w"); //open the counter data file to writing. (overwrite the old data)
if (!$counter_fp) //if couldn’t open for writing
echo "\n<B>ERROR: could not open the counter data file for writing.</B><BR>\n";
$counter_hitcount=($c<0)?$counter_initial:$c; //sets the hit counter to $c if it’s valid(>=0), or to initial number if not valid(<0)
@fwrite($counter_fp,(string)$counter_hitcount); //writes the new counter hit to the file
@fclose($counter_fp); //closes the file
}

/* Checkes if the cookie exists. if exists, the counter isn’t advanced. if not exists, advance the counter by 1. $print determines if to print the counter. */
function CounterAutoIncrease($print=false)
{
global $counter_visited;

if (!$counter_visited) //if the counter wasn’t visited yet
CounterIncrease(); //increase counter by 1
if ($print) //if to print the counter
CounterPrint(); //prints the counter
}




CounterAutoIncrease(true);
?>

----------------------------------------------------------------------

counter_conf.txt:

<?

$counter_file="cnt.dat"; //path to the counter data file
$counter_style="image"; // ’image’ OR ’text’
$counter_cookie_with=true; //boolean variable determines to use cookies or not
$counter_cookie_time=86400; //in seconds. one day cookie lifetime (set to 0 to have it to window life time)
$counter_cookie_name="countervisit"; //name of the cookie
$counter_length=5; //number of digits to show
$counter_zero_lead=true; //true/false. weather to show leading zeros or not
$counter_initial=1; //initial number of counter
$counter_image_width=-1; //the size of the digit images when image style enabled (-1, image size)
$counter_image_height=-1; //the size of the digit images when image style enabled (-1, image size)
$counter_font_color="#993399"; //the color of the textual digits
$counter_font_size=3; //the size of the textual digits
/* initialize digits pictures paths: */
$counter_digit[0]="digits/digital/0.gif";
$counter_digit[1]="digits/digital/1.gif";
$counter_digit[2]="digits/digital/2.gif";
$counter_digit[3]="digits/digital/3.gif";
$counter_digit[4]="digits/digital/4.gif";
$counter_digit[5]="digits/digital/5.gif";
$counter_digit[6]="digits/digital/6.gif";
$counter_digit[7]="digits/digital/7.gif";
$counter_digit[8]="digits/digital/8.gif";
$counter_digit[9]="digits/digital/9.gif";

?>


-----------------------------------------------------------------------

יש את הקובץ cnt שהוא רק בשביל לשים את מספר מונה המבקרים

תודה לעוזרים!!!!!

23/06/2006 00:49:21 devil kide
אני לא יודע PHP , אבל תנסה לעשות בדיקה, כל שעה 12 בלילה ( 00:00) המונה מתאפס חזרה.
עמודים: 1