PHP Live Counter problem!!

Status
Not open for further replies.

╬Switch╬

In the zone
I got this code from webdesign.org it does work,
Code:
<? 
//DBase Name: 
$opt_connected_cfgbase = "base"; 
//Username : 
$opt_connected_cfguser = "user"; 
//PassWord : 
$opt_connected_cfgpass = "pass"; 
//Path : 
$opt_connected_cfghote = "localhost"; 
// Amout of time to consider a user active 
$nb_connected_connexion=300; // 5 minutes 
 
// Connexion to the database 
$base_connected=mysql_connect($opt_connected_cfghote, $opt_connected_cfguser,$opt_connected_cfgpass); 
if (!$base_connected) 
{ 
("<center>Error connecting to the Database </center>"); 
exit(); 
} 
 
// Database selecting 
if (! mysql_select_db("$opt_connected_cfgbase",$base_connected)) 
{ 
mysql_close($base_connected); 
print("<center>Error connecting to the Database</center>"); 
exit(); 
} 
 
// time 
$time_connected=date("U"); 
 
// Get IP 
[B][COLOR=red]$ip_connected=$REMOTE_ADDR[/COLOR][/B]; 
 
// Search IP in the DB 
$query_connected="select * from nb_connected where ip='$ip_connected'"; 
$result_connected=@mysql_query($query_connected,$base_connected); 
 
if (!$result_connected) 
{ 
mysql_close($base_connected); 
print("<center>Could not execute request </center>"); 
exit(); 
} 
 
$nb_connected=@mysql_num_rows($result_connected); 
if ($nb_connected) 
{ 
// Update the connexion 
$query_connected="update nb_connected set time='$time_connected' where ip='$ip_connected'"; 
$result_connected=@mysql_query($query_connected,$base_connected); 
} 
else 
{ 
// Create connexion 
$query_connected="insert into nb_connected (ip, time) values ('"; 
$query_connected.=$ip_connected; 
$query_connected.="', '"; 
$query_connected.=$time_connected; 
$query_connected.="')"; 
$result_connected=@mysql_query($query_connected,$base_connected); 
} 
 
// Calculate maximum time of connexion 
$time_max_connected=$time_connected-$nb_connected_connexion; 
 
// Deleting Maximum time connexion from DB 
$query_connected="delete from nb_connected where time<'$time_max_connected'"; 
$result_connected=@mysql_query($query_connected,$base_connected); 
 
// Close connexion to DB 
mysql_close($base_connected); 
?>
But it is displayed along with the following error:
Notice: Undefined variable: REMOTE_ADDR in d:\web\tools\easyphp\www\counter\index.php on line 35

Can anyone help me get it right:?:
 
Last edited:

tuxfan

Technomancer
This needs a MySQL database. Hope you have created one and connected with this! However, I have seen simpler PHP counters that don't need a DB. They are lighter on the system.
 
OP
╬Switch╬

╬Switch╬

In the zone
@utsav handa:
Ill try that.Thanks.
__________
@tuxfan
The couneter I have above counts the number of people online at that instant.
The ones you mention (ones which are made using text files) count number of visits to a page.
 
Last edited:
Status
Not open for further replies.
Top Bottom