php统计IP以及在线人数的统计
1.用JS调用文件count.php 在你需要加入统计的的地方加入<script src="count.php"></script> 实际运用中注意修改路径!
2.php环境必须支持putenv()函数,可以统计昨日访问,今日访问,在线人数,您访问的次数。
3 . 在count.php相同目录建立以下文件 count,temp,online,新建文本文档count.txt 然后去掉扩展名就是文件count了;如果是Linux主机请把这三个文件属性设为777.
count.php文件代码:
<?
$file = "count"; // 记数文件名称
$startno = "1000"; // 起始数值
$tempfile = "temp";
$t_now = time();
$t_array = getdate($t_now);
$day = $t_array['mday'];
$mon = $t_array['mon'];
$year = $t_array['year'];
if (file_exists("$file")) {
$count_info=file("$file");
$c_info = explode(",", $count_info[0]);
$total_c=$c_info[0];
$yesterday_c=$c_info[1];
$today_c=$c_info[2];
$lastday=$c_info[3];
} else {
$total_c="$startno";
$yesterday_c="0";
$today_c="0";
$lastday="0";
}
if ( !isset($HTTP_COOKIE_VARS["countcookie"]) || $HTTP_COOKIE_VARS["countcookie"] != $day) {
$your_c=1;
$lockfile=fopen("temp","a");
flock($lockfile,3);
putenv
相关文档:
连接:
$conn=mysql_connect ("localhost:3306", "username", "password");
mysql_select_db("DBname");
读:
$exec="select * from stu";
$result=mysql_query($exec);
while($rs=mysql_fetch_object($result))
{
echo $rs->id." & ......
假如有两个表: user 和 articles 表
结构:
user: (id, name)
articles: (id,user_id,title,content)
其中user.id 和 user_id 关联
在user的 model中的 relations方法里面加:
return array('articles'=>array(self::HAS_MANY,'articles','user_id'));
在articles的 model中的 relations方法里面加:
......
<?
include 'conn.php';
$_pagenob=10; //每页规定的信息数目
//获取当前页
if(isset($_GET["page"]))
{
$_page = intval( $_GET['page'] );
}
else
{
$_page=1;
}
//查询数据总数
$_query="select count(*) as acount from news";
$_result=mysql_query($_query);
$_row=mysql_fetch_row($_result);
......
Memcache函数库是在PECL(PHP Extension Community Library)中,主要作用是搭建大容量的内存数据的临时存放区域,在分布式的时候作用体现的非常明显,否则不建议使用。
memcache函数所有的方法列表如下:
参考http://www.php.net/manual/zh/function.Memcache-add.php
Memcache::add - 添加一个值,如果已经存在,则返回f ......