//你的mysql的用户名$db,首先是创建MYSQL数据库表
分类:热门新闻

刚用PHP写了二个网址在眼线数的次第,请大家进入携湿疹!笔者是用PHP+MYSQL来写的,原理:网址在间谍数的程序代码+后台有MYSQL数据库扶持,能够直接总结出网址当前的在窥伺者数。首先本人创设MYSQL数据库表。CREATE TABLE tablename (田野 type(max_length) DEFAULT 'default_value' (NOT卡塔尔国NULL}能够动用的SQL语句。CREATE TABLE useronline (timestamp int(15卡塔尔国DEFAULT '0' NOT NULL,ip varchar(40卡塔尔 NOT NULL,file varchar(100卡塔尔(قطر‎ NOT NULL,P本田CR-VIMAEscortY KEY (timestamp卡塔尔,KEY ip (ip卡塔尔(قطر‎,KEY file (fileState of Qatar卡塔尔国;下边大家是PHP脚本,首先笔者定义MYSQL的消息。$server = localhost; //你的服务器$db_user = root; //你的mysql的用户名$db_pass = password; //你的mysql的密码$database = users; //表的名字设置计算的光阴(多少秒内在窥探数卡塔尔$timeoutseconds = 300;取当前几日子。$timestamp = time(卡塔尔国;上边的全部代码:?php$server = localhost; //your server$db_user = root; //your mysql database username$db_pass = password; //your mysql database password if any$database = users; //the db name$timeoutseconds = 300;//timeoutseconds limit//get the current time$timestamp = time();//calculate the lowest timestamp allowed$timeout = $timestamp-$timeoutseconds;?连接mysqlmysql_connect('localhost', 'username', 'password'State of Qatar;也允许使用变量情势。mysql_connect($server, $db_user, $db_pass卡塔尔(قطر‎;若是mysql数据库未有密码的话可以接受下边代码连接mysql_connect($server, $db_user卡塔尔国;查询数据库的代码:mysql_db_query('database', 'query'卡塔尔(قطر‎;大家假使有来访的客人就要扩展一条记下。$insert = mysql_db_query($database, INSERT INTO useronline VALUES('$timestamp','.$_SERVER['REMOTE_ADDR'].','.$_SERVER['PHP_SELF'].'卡塔尔);假诺顾客用错误音信的话,那样管理。if(!($insertState of QatarState of Qatar{print Useronline Insert Failed ;}然后达成当高出设置的年华就删除该客商记录。$delete = mysql_db_query($database, DELETE FROM useronline WHERE timestamp$timeout卡塔尔;相似给出删除记录出错的管理。if(!($delete卡塔尔国卡塔尔国 {print Useronline Delete Failed ;}上面大家减轻数据库中不一致IP的标题$result = mysql_db_query($database, SELECT DISTINCT ip FROM useronline WHERE file='.$_SERVER['PHP_SELF'].' );使用mysql_num_rows(query卡塔尔;来总计客户,代码如下。$user = mysql_num_rows($result卡塔尔国;最终关闭数据库。mysql_close(卡塔尔国;展现在线的食指。if($user == 1卡塔尔(قطر‎ {print(1 user online/n卡塔尔(قطر‎;} else {print($user users online/nState of Qatar;}最后把上边代码写成叁个PHP文件如下。?php//Put your basic server info here$server = localhost; //normally localhost$db_user = root; //your MySQL database username$db_pass = password; //your MySQL database password$database = users;$timeoutseconds = 300; //it will delete all people which haven't refreshed(so probbably are// offline or inactive) in $timieoutseconds time (so it actually checks the people that are active in the last// $timeoutseconds seconds)//this is where PHP gets the time$timestamp = time();//counts the timeout, all people which have been seen last online in earlier than this timestamp, will get removed$timeout = $timestamp-$timeoutseconds;//connect to databasemysql_connect($server, $db_user);//add the timestamp from the user to the online list$insert = mysql_db_query($database, INSERT INTO useronline VALUES('$timestamp','.$_SERVER['REMOTE_ADDR'].','.$_SERVER['PHP_SELF'].'));if(!($insert)) {print Useronline Insert Failed ;}//delete the peoples which haven't been online/active in the last $timeoutseconds seconds.$delete = mysql_db_query($database, DELETE FROM useronline WHERE timestamp$timeout);if(!($delete)) {print Useronline Delete Failed ;}//select the amount of people online, all uniques, which are online on THIS page$result = mysql_db_query($database, SELECT DISTINCT ip FROM useronline WHERE file='.$_SERVER['PHP_SELF'].' );if(!($result)) {print Useronline Select Error ;}//Count the number of rows = the number of people online$user = mysql_num_rows($result);//spit out the resultsmysql_close();if($user == 1) {print(1 user online/n);} else {print($user users online/n);}?

PHP实例教程:网址在窥探数的程序代码,后台有MYSQL数据库辅助。能够一贯总计出网址当前的在窥伺者数。

首先是创设MYSQL数据库表。

以下为援用的剧情:
CREATE TABLE tablename (
field type(max_length) DEFAULT 'default_value' (NOT) NULL
}

能够应用的SQL语句。

以下为援引的剧情:
CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);

上面大家起始采纳PHP脚本,首先定义MYSQL的消息。

$server = "localhost"; //你的服务器

$db_user = "root"; //你的mysql的顾客名

$db_pass = "password"; //你的mysql的密码

$database = "users"; //表的名字

安装总计的时光(多少秒内在眼线数卡塔尔

$timeoutseconds = 300;

取当前时间。

$timestamp = time();

地方的欧洲经济共同体代码:

以下为援用的源委:
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')");

连接mysql

mysql_connect('localhost', 'username', 'password');

也允许行使变量情势。

mysql_connect($server, $db_user, $db_pass);

即便mysql数据库未有密码的话能够利用上边代码连接(当然建议咱们确定要安装好和睦的密码,那样最少黑客得要解密啊)

mysql_connect($server, $db_user);

查询数据库的代码:

mysql_db_query('database', 'query');

咱俩若是有来访的客人将要增添一条记下。

以下为援用的剧情:
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')");

然后大家提交假设客商用错误音讯的管理方式。

以下为援引的原委:
if(!($insert)) {
print "Useronline Insert Failed > ";
}

下一场大家得落到实处当赶过大家设置的时日大家将要删除该客户记录。

$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp

一直以来给出删除记录出错的拍卖。

以下为援引的开始和结果:
if(!($delete)) {
print "Useronline Delete Failed > ";
}

上边大家呈现数据库中有稍许个例外的IP

$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='".$_SERVER['PHP_SELF']."' ");

大家应用

mysql_num_rows(query);

来总计顾客,代码如下。

$user = mysql_num_rows($result);

提及底我们要关闭数据库。

mysql_close();

来得在线的人口。

以下为援用的内容:
if($user == 1) {
print("1 user onlinen");
} else {
print("$user users onlinen");
}

终极把地点代码写成四个PHP文件如下。

以下为援引的源委:

//Put your basic server info here
$server = "localhost"; //normally localhost
$db_user = "root"; //your MySQL database username
$db_pass = "password"; //your MySQL database password
$database = "users";
$timeoutseconds = 300; //it will delete all people which haven't refreshed(so probbably are
// offline or inactive) in $timieoutseconds time (so it actually checks the people that are active in the last
// $timeoutseconds seconds)
//this is where PHP gets the time
$timestamp = time();
//counts the timeout, all people which have been seen last online in earlier than this timestamp, will get removed
$timeout = $timestamp-$timeoutseconds;
//connect to database
mysql_connect($server, $db_user);
//add the timestamp from the user to the online list
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
//delete the peoples which haven't been online/active in the last $timeoutseconds seconds.
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestampif(!($delete)) {
print "Useronline Delete Failed > ";
}
//select the amount of people online, all uniques, which are online on THIS page
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='".$_SERVER['PHP_SELF']."' ");
if(!($result)) {
print "Useronline Select Error > ";
}
//Count the number of rows = the number of people online
$user = mysql_num_rows($result);
//spit out the results
mysql_close();
if($user == 1) {
print("1 user onlinen");
} else {
print("$user users onlinen");
}
?>

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处://你的mysql的用户名$db,首先是创建MYSQL数据库表

上一篇:【威尼斯登录首页】//初始化标志点 private $offset=0 下一篇:php 遍历目录
猜你喜欢
热门排行
精彩图文