Free php script for online user.download free php script to see how many users are online.this free php is applicable in your website also where you can show your visitors with this free php scripts that how many users are online.
![]() |
| Free Php script For online user |
How does Free php script for online user work.
When a visitor or user visits your website than with this free php script his ip address along with the timesatamp is inserted into a table that i will desribe now.this free php creates a timeout period.free php scripts For creating a table to show online user
CREATE TABLE `usersonline` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `ip` VARCHAR( 20 ) NOT NULL , `time` INT NOT NULL ) ENGINE = INNODB;
Three basic component of the above table.
First is id-id is your primery key.Second is ip-ip is the ip address of visitor.
Third is time-A timestamp in unix language that shows when the last visitor was seen.
Main Function of free php scripts
function usersonline() {
// Time in seconds that user is assumed to visit site
$timeout = 300;
// Insert users ip into table
mysql_query("INSERT INTO usersonline
VALUES(
'',
'".$_SERVER['REMOTE_ADDR']."',
UNIX_TIMESTAMP()
)
") or die(mysql_error());
// Delete timed out records in table
$deadline = time() - $timeout;
mysql_query("DELETE FROM usersonline WHERE time < '".$deadline."'") or die(mysql_error());
// Query table for distinct IP's and return result
$result = mysql_query("SELECT DISTINCT ip FROM usersonline") or die(mysql_error());
return mysql_num_rows($result);
}
And now the rest of the work will be done by this free php scripts for online user so below is the free php .Free php script to show online User
";
24 }
25
26 //delete values when they leave
27 $delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
28 if(!($delete)) {
29 print "Useronline Delete Failed > ";
30 }
31
32 //grab the results
33 $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
34 if(!($result)) {
35 print "Useronline Select Error > ";
36 }
37
38 //number of rows = the number of people online
39 $user = mysql_num_rows($result);
40
41
42 //spit out the results
43 mysql_close();
44 if($user == 1) {
45 print("$user user online\n");
46 } else {
47 print("$user users online\n");
48 }
49 ?>
This is the main function code of free php for online user.this free php script is the combination of two Mysql query where in first we set up a table and in second we create a function.this function of free php is universal that's why you can call it from anywhere in your php script.in this free php script a timeout variable is being set to seconds and our assumption behind setting timeout variable to second is visitor is viewing a single page and then going to another page of our website and after the time has gone our assumption is visitor has gone to another site or left our website.now this mysql query's function is putting all user information into the table.the idea behind using UNIX timestamp() function is it is quite similar to time function of php but it is much prefferable than the php 's time function because of not using periods.we are also using a deadline variable which decide which values are going to be deleted form the table.
How to show present online user with this free php script
For this purpose we are using Distinct ip which will display how many records are there in the table and the number of records left will be considered as number of online user in this function of free php.
Conclusion
so download free php scripts for online user is using two mysql queries first this free php will create a table to keep records like ip address and timestamp of our visitor and second function of free php script for online user is function.which is assigning a values into tables.so download php script to show online user or copy paste this free php.
Php Script Code For Forum
Blogspotinfo.com provides you php code script to build your own Forum in your website.you will get answer of your...
Free Php code script to Ban IP Address
PHP FREE CODE SCRIPT TO BAN IP ADDRESS AT BLOGSPOTINFO.COM
Free Php script code:Contact us Form For Website
Blogspotinfo.com provides you the php script code to create Contact us form for your...

0 comments :
Post a Comment