FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to connect them





megamass
i have two sripts : one of them counts visits per day (writes to counter.txt), another one - total visits (writes to counter_2.txt). is it possible to put them together?

per day:
Quote:
<?php


//get the current date (formatted as "08/10/2005")
$today = date ("d/m/Y");

//open the file
//line 0 (1 for non programmers ) contains the date
//line 1 (2 for non programmers )contains the number of visits
$file = file("counter_2.txt");
$line = 0;
foreach ($file as $data)
{
if ($line == 0)
//line 0 => format the stored time
$time = date("d/m/Y", $data);
if ($line == 1)
//line 1 => stored visitors
$count = $data;
$line++;
}

//if the day isn't the current day, set the count to zero
if ($time != $today)
$count = 0;

//add one for the current visitor
$count = $count + 1;

// Display the number of hits
echo "<p>Today: " . $count . "</p>";
// To disable output to webpage quote the above line using //

//construct the 2 line from the count.txt
$lines2write = time() . "\n" . $count;

//write the lines to the file
$fp = fopen("counter_2.txt", "w");
fwrite($fp, $lines2write);
fclose($fp);

?>


total:
Quote:
<?php

$fp = fopen("counter.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;

// Display the number of hits
echo "<p>Total: " . $count . "</p>";
// To disable output to webpage quote the above line using //

$fp = fopen("counter.txt", "w");
fwrite($fp, $count);
fclose($fp);

?>
Grimboy
You mean like shoving them in the same script? I don't see why not.
BlackSkad
In place of saying it might be possible, just do it Smile That's more of a help to megamass then a little sentence...
Code:
<?php
//get the current date (formatted as "08/10/2005")
$today = date ("d/m/Y");

//open the file
//line 0 (1 for non programmers ) contains the date
//line 1 (2 for non programmers )contains the number of visits today followed by a | and the number of visitors of all times...
$file = file("counter_2.txt");
$line = 0;
foreach ($file as $data)
{
   if ($line == 0)
      //line 0 => format the stored time
      $time = date("d/m/Y", $data);

   if ($line == 1)
      //line 1 => stored visitors today|all visitors
       $tmp = explode ("|", $data);
      $todayCount = $tmp[0];
      $allCount = $tmp[1];

   $line++;
}

//if the day isn't the current day, set the count to zero
if ($time != $today)
   $count = 0;

//add one for the current visitor
$todayCount++;
$allCount++;


// Display the number of hits
echo "<p>Today: " . $todayCount . "</p>";
echo "<p>Today: " . $allCount . "</p>";
// To disable output to webpage quote the above line using //

//construct the 2 line from the count.txt
$lines2write = time() . "\n" . $todayCount."|".$allCount;

//write the lines to the file
$fp = fopen("counter_2.txt", "w");
fwrite($fp, $lines2write);
fclose($fp);
?>
megamass
BlackSkad - thanks you again Wink
megamass
i tried to make output text like this : visits: 5/1786 ( 5 - todays, 1786 - total ) but i got an error . i change it to:

Code:
echo "<p>Visits: " . $todayCount . "/" . $allCount . "</p>";


what is wrong ?
BlackSkad
Euhm, could you give the specific error-message, because your code-sentence looks ok...
It should work...
megamass
sorry, i made a mistake while typing code in my script editor. everything works fine. thanks for help.
megamass
a little problem with this sripts . it doesn't reset visits per day to 0 every day. i can't find an error :/
BlackSkad
Sorry for the rather late response, but I'm not at home and haven't got a lot of time.
I forgot to change something in the script. Just replace this line
Code:

//if the day isn't the current day, set the count to zero
if ($time != $today)
   $count = 0;

with the following
Code:

//if the day isn't the current day, set the count to zero
if ($time != $today)
   $todayCount = 0;


This should work...
megamass
BlackSkad wrote:
Sorry for the rather late response, but I'm not at home and haven't got a lot of time.
I forgot to change something in the script. Just replace this line
Code:

//if the day isn't the current day, set the count to zero
if ($time != $today)
   $count = 0;

with the following
Code:

//if the day isn't the current day, set the count to zero
if ($time != $today)
   $todayCount = 0;


This should work...


yes , now it works Smile
Related topics
How can I connect to cpanel?
How can I connect to cpanel?
How can I connect to cpanel?
How can I connect to cpanel?
addon domains / rndc: connect failed
Must cpanel be 2082? I can't connect
TI-Connect software won't run on my xp
phpBB : Critical Error Could not connect to the database
php can't connect to mysql
SMF install: Unable to connect to FTP server
HOW TO CONNECT MY SITE TO AN ACCESS DATA BASE??
HELP! Can't connect to the internet
MP3 Player will not connect
Parent Connect
error: Can't connect to local mysql server through socket
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.