当前位置: 首页 > 图文教程 > 网络编程 > PHP > 坏狼php学习 计数器实例代码

PHP
PHP删除MYSQL数据库中所有表的代码
php教程:php设计模式介绍之注册模式
php教程:php设计模式介绍之伪对象模式
PHPnow轻松打造专业PHP服务器环境
php教程:php设计模式介绍之策略模式
php教程:php设计模式介绍之迭代器模式
Windows环境下Apache与Tomcat共存
简单学习php遇到的主要问题
php教程:php设计模式介绍之观测模式
php教程:php设计模式介绍之规范模式
php教程:php设计模式介绍之代理模式
php教程:php设计模式介绍之装饰器模式
Perl操作mysql数据库的方法
php教程:php设计模式介绍之适配器模式
PHP单件模式和命令链模式的基础知识
PHP大师指点:优秀的PHP代码怎么来?
PHP开发的Myers 订单跟踪系统 (MOTS)
PHP控制网页过期时间的程序
Cannot modify header information出错的原因
PHP 5.3的date_create_from_format()函数

PHP 中的 坏狼php学习 计数器实例代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 76 ::
收藏到网摘: n/a

首先进入phpmyadmin建立1个数据库命名为db,然后建立几个表.name是用户badwolf的访问记数,IP是存来访IP,new是存数. 然后建立文件如下,第1步骤连数据库,然后写,然后读.
复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "db";
//抓ip
$ip = getenv ("REMOTE_ADDR");
//建立连线--透过(伺服务器位置,使用者名称,使用者密码)
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
//准备好 sql语法 此语法为新增资料
$sql = "INSERT INTO `num` ( `name` ,`ip`, `new` ) VALUES ('badwolf','$ip','1');";
//选取你想要处理的资料库
mysql_select_db($mysql_database,$conn);
//进行查询
$result = mysql_query($sql);
//结果并且释放连线
mysql_close($conn);
//------------------------------------------------------------------
//以下为印出资料
//建立连线 透过(伺服务器位置,使用者名称,使用者密码)
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
//准备好 sql语法 此语法为读取资料
$sql = "SELECT COUNT(*) FROM `num` WHERE name='badwolf' ";
//进行查询
$result = mysql_db_query($mysql_database,$sql,$conn);
//将查询后的结果 抓出
$row = mysql_fetch_row($result);
//印出该资料的所有栏位
//print_r($row);
//清除查询后的结果
mysql_free_result($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>坏狼安全网php计数器</title>
<style type="text/css">
<!--
.STYLE1 {font-size: larger}
.STYLE3 {font-size: 36px; font-family: "宋体"; font-weight: bold; color: #FF0000;}
-->
</style>
</head>
<body>
<div align="center" class="STYLE1">
<p>坏狼安全网php计数器</p>
<h1>开站至今已经有<span class="STYLE3"><?=$row[0]; ?></span>人次</h1>
</div>
</body>
</html>