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


Need script





megamass
hellow

1) i need script ( php or java ) which displays:
* visitors today
* total visitors
2) one more script which displays live clock and date

script should be displayed as basic text.
Lady Elensar
ever heard of Google?

go to google, typ: script java php total visitors.. or something like that.
and... click! (on a link) Very Happy

but if you're to lazy:

http://www.hotscripts.com/PHP/Scripts_and_Programs/Counters/more4.html

I think there something for you, at this site.. have a look, I should say. Wink
BlackSkad
Well, I was thinking the same, but I wasn't as lazy Wink
Let's see:
Google for your visitors
Google for you date and time

And hotscript (link in post above) is a magnificent source!

BlackSkad
mwm
You might also look at the scripts offered in cpanel. There are some counters available I believe. Always easier to have it done for you...

-mwm
megamass
i have solved problems with these to sripts .

now i need help . maybe there is a script or command line to solve this question:

in top bar i press for example < SCRIPTS> and the script scrolls me down to that place where is written about scripts
BlackSkad
I don't realy think such a script exist, but again, you can use google.

If you don't want to use only javascript, you can manage it in html too, but not with a topbar to enter text.

let's say you have a link on top of your page:
Code:
<a href="http://yoursite.com/page.htm#scripts">scripts</a>


And a little lower on your page, an anchor like this:
Code:
<a name="scripts"></a>


By clicking the link on top, your page will scroll down to the place of the anchor.

I hope you understand what I've written Smile
BlackSkad
megamass
BlackSkad wrote:
I don't realy think such a script exist, but again, you can use google.

If you don't want to use only javascript, you can manage it in html too, but not with a topbar to enter text.

let's say you have a link on top of your page:
Code:
<a href="http://yoursite.com/page.htm#scripts">scripts</a>


And a little lower on your page, an anchor like this:
Code:
<a name="scripts"></a>


By clicking the link on top, your page will scroll down to the place of the anchor.

I hope you understand what I've written Smile
BlackSkad


thank you . it really works Smile
megamass
how to improve this script ? i would that every day the counter would reset number of visits to 0

Quote:
<?php

/**
* The counter.txt file stores the information for the hits
* All you need to do is upload the counter.txt file and
* the counter.php file to your website and then
*
* Add this line of code on your page to be counted:
* &lt;?php include "counter.php"; ?&gt;
*/

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

// Display the number of hits
echo "<p>I&scaron; viso lankytojų: " . $count . "</p>";
// To disable output to webpage quote the above line using //

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

?>
BlackSkad
Code:
/**
* The counter.txt file stores the information for the hits
* All you need to do is upload the counter.txt file and
* the counter.php file to your website and then
*
* Add this line of code on your page to be counted:
* &lt;?php include "counter.php"; ?&gt;
*/

//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.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>I&scaron; viso lankytoju;: " . $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.txt", "w");
fwrite($fp, $count);
fclose($fp);

The modifications store the date on the first line and the count on the second. It opens it and read the 2 lines. Line 1 becomes $time and line 2 $count.
Check if the stored time $time is different from the current date. If yes, set the count to zero.
Add one visitor for the current one. Then the output.
Construct the new line for the counter.txt and write it to the file.

It should work, but I haven't tried it yet. So don't shoot me if it doesn't Smile
BlackSkad
megamass
BlackSkad - something is wrong . counter stops working after 1 visitor :/
BlackSkad
Yeah, found it Smile Just replace the last lines by these. I forgot to change the second parameter of fwrite();

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


Greatz,
BlackSkad
megamass
it works Very Happy now waiting for tomorow to see if the counter resets to zero Very Happy
BlackSkad
Normaly it has to looking at the behaviour with the error before Smile
You should know it by now, but normaly it does.

Greatz,
BlackSkad
megamass
simple question, but i dont know how to solve the problem

Quote:
..........st.net</a> </p>
<p><? include "counter_2.php"; ?>< ? include "counter.php"; ?></p>


i don't understand why counter_2 and counter doesn't stay in the same line when i open my web page Confused
BlackSkad
Are they both like the script above?
Then it's pretty obvious. You got a situation like this:
Code:
<p>
<p>Counter 1</p>
<p>Counter 2</p>
</p>


The end of an p-tag is automatticaly a new line, even if it is not indicated. It's an alinea in fact (don't know wheter alinea exists in English). To resolve it, just remove the inner <p>-tags.
megamass
is it possible to make this script to count only uniq visitors?
BlackSkad
I'm afraid that will need huge modifications to the script. And there are loads of secure and accurate counter-script out there who only count unique visitors.
It would be a wast of my time now to make such a script, maybe I might make such a script in the future,... once, ... when I find the time... As for now, take a look at google.com, hotscripts.com or sourceforge.net Wink

BlackSkad
megamass
Code:
<?php

$file = "counter.txt";
$user_ip = $_SERVER['REMOTE_ADDR'] . "\n";
$ip_list = file($file);
$visitors = count($ip_list) - 1;

if (in_array($user_ip, $ip_list))
   {
   echo ("$visitors");
   } else {
   
   $fp = fopen($file,"a");
   fwrite($fp, "\n$user_ip");
   fclose($fp);
   
   $visitors++;
   echo $visitors;
   }

?>


how to make that it would post not only numbers but also the text ( Today: 4 ) and what i have to change that it would reset visits every day?
BlackSkad
This should do the job...
Code:
<?php
//the user's ip
$user_ip = $_SERVER['REMOTE_ADDR'] . "\n";

//the data-file, on the first line goes the date, ip's follow on the next lines
$file = "counter.txt";
$ip_list = file($file);

//check if the date in the file is the same as the current day
if ( date("d/m/Y", $ip_list[0]) != date ("d/m/Y"))
{
   $ip_list = array(time());

   //write the changes to the file (will only contain the date)
   $fp = fopen($file,"w");
   fwrite($fp, time());
   fclose($fp);
}

//count the visitors
$visitors = count($ip_list) - 2;

//set the display-text, so you only need to change it once if you wan to change it:)
$display_text = "Today: ";

if (in_array($user_ip, $ip_list))
{
   echo $display_text.$visitors;
}
else
{
   $fp = fopen($file,"a");
   fwrite($fp, "\n$user_ip");
   fclose($fp);

   $visitors++;
   echo $display_text.$visitors;
}

?>
megamass
something is wrong:

first user: Today: 0
second user: Today: 1
third user: Today: 3

counter.txt after 3 users looks like this:

Quote:
1131206943
85.206.215.33

85.206.215.32

85.206.215.31
BlackSkad
Hmm, I made some changes and tried it myself (didn't do it with the previous, I hadn't got the time) Again, serious now, this should work fine, please tell me if it doesn't...

Code:
<?php
//the user's ip
$user_ip = $_SERVER['REMOTE_ADDR'] . "\n";

//the data-file, on the first line goes the date, ip's follow on the next lines
$file = "counter.txt";
$ip_list = file($file);

//check if the date in the file is the same as the current day
if ( date("d/m/Y", $ip_list[0]) != date ("d/m/Y"))
{
   $ip_list = array(time());

   //write the changes to the file (will only contain the date)
   $fp = fopen($file,"w");
   fwrite($fp, time());
   fclose($fp);
}

//count the visitors
$visitors = count($ip_list) - 1;


//set the display-text, so you only need to change it once if you wan to change it:)
$display_text = "Today: ";

if (in_array($user_ip, $ip_list))
{
   echo $display_text.$visitors;
}
else
{
   $fp = fopen($file,"a");
   fwrite($fp, "$user_ip");
   fclose($fp);

   $visitors++;
   echo $display_text.$visitors;
}

?>
megamass
now the script always post Today: 1 . every user see the same
BlackSkad
No way, impossible, it shouldn't. Try and add some different ip's to the file. If you access the page with 1 computer, it's normal that you only have 1 visitor, as it counts unique ip's only.
Could you give me the page where the counter is located, so I can check it out with my pc Smile

Greatz,
BlackSkad
megamass
you can see it on my test page.

http://test.mdstudio.frihost.net

all user will see the same - Today: 1

i checked counter.txt after every visit, and i saw that after every visit there is just one IP - last user IP.
BlackSkad
weird, maybe replace this line
Code:

   fwrite($fp, "$user_ip");

with this one
Code:

   fwrite($fp, "\n$user_ip");
megamass
you know, it doesn't work. thank You for your help. see you later Smile
BlackSkad
I think I know what was wrong.
The txt-file looked like this, which is a combination of the date and the last user-ip:
Code:
113126181781.164.130.95

As the code sees the first file-line as the date, it takes the whole line, so date AND ip. Making your txt-file look as below and adding the '\n' I mentioned 2 posts above, should do it.
Code:
1131261817
81.164.130.95

Well, I hope so Very Happy

BlackSkad
Related topics
Which is your favourite weblog Script?
Chat script
Script Upload (obiefileman)
script backup database
Script run background
Can someone make me a php script?
target = _parent redirect script?
Bookmark Script:
Some Script Show
Image transparency script
A script for Loading
Set As Home Page Script (IE Only)
Where I can find a 3d chat script
Un script installer? laissez faire frihost!
Need a script - navigation
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.