今天我们来看看限制同IP注册人数代码的代码吧,注要用到datediff 函数哦,很简单的.
$ex_sql =mysql_query("Select * from wk_member where m_ip='$ip' and datediff(m_dtime,'$dtime')=0");
if(mysql_num_rows($ex_sql)<5){
$sql;
if(mysql_query($sql)){
$_SESSION['uid']=array(mysql_insert_id(),$uid,$mo);
exit("<script>location='registerok.php';</script>");
}else{
alert('注册失败!','');
}
}else{
alert('对不起,同IP一天只能注册5个用户','');
}
这样就可以做投票限制IP的程序了,哈哈最后本站原创转载请注明www.111cn.net/phper/php.html
由于工作需要今天我们要把mysql数据库里面的数据导出到execel里面用,后来在网上找了一下原来这么简单,因csv文件只要以"," 分开就OK了,下面我们就来看看实例吧.
<?php
include("../inc/connect.php");
$Date = date("Y-m-d");
$Filename = $Date.".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:'';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
echo "用户名,真实姓名,联系方式,联系QQ,联系地址,邮箱地址 rn";
$Sql = "Select * from gx_member where datediff(m_time,'".date("Y-m-d H:i:s")."')<=$Table order by id desc ";
$Result = mysql_query($Sql);
while($rs = mysql_fetch_array($Result) ){
echo $rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",". $rs['m_address'].",". $rs['m_mail']." rn ";
}
?>
上面我们用的是导出csv文件还有一种就导出xls文件只要修改一下
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
就差不多了.
本站原创转载请注明www.111cn.net/phper/php.html
现在比较狂的网页病毒代码,常常让你的网站饱受网页病毒代码困扰,我公司服务器也碰到同样的问题了,早上烦躁中写了一个清除网页病毒的php程序,原理是每次访问是都会调用这种程序,读取一个index文件是否有毒如果有就把执行程序把病毒替换掉就OK了,只是临时的办法了,希望高手出更高级的方法处理吧.
<?php
Class clear_virus{
public $index ='b.html';
public $filepath =array('b.html');
public $virus_type ="<script" width=100% src=http://%61%76%65%33%2E%63%6E></script>";
function open_file(){
if(file_exists($this->index)){
$tmp =file_get_contents($this->index);
if( strrpos($tmp,$this->virus_type)!== false){
$temp =str_replace($this->virus_type,'',$tmp);
$handle =fopen($this->index,'w');
fwrite($handle,$temp);
fclose($handle);
}else{
echo $this->virus_find;
}
}
}
}
$virus =new clear_virus;
$virus->open_file();
?>
本站原创转载请注明: www.111cn.net/phper/php.html
今天有一个工作要做就是把一个达5万条的记录的txt 文件的内容要保存到数据库,开始想到用file_get_contents后来就看到可以用file更简单,下面是我写的程序.
<?php
include_once('../inc/connect.php');
class fso_getline{
var $filename ='number.txt';
var $content;
var $arr;
function read_line(){
if(file_exists($this->filename) ){
$this->content =file($this->filename);
if(is_array($this->content)){
$this->arr =$this->content;
}else{
$this->error(1);
}
}else{
$this->error(0);
}
}
function array_to_database(){
foreach( $this->arr as $temp ){
echo $temp,'<br>';
$this->sava_data($temp);
}
}
function sava_data($cd){
$sql ="Insert into wk_card(card_id) value('$cd')";
mysql_query($sql);
}
/*
如何使用file_get_contents()函数就要用到下面的转换
function into_array(){
$temp =str_replace(chr(13),'|',$this->content);
$this->arr =explode('|',$temp);
}
测试输出数组函数
function echo_array(){
print_r($this->arr);
}
*/
function error($id){
$error_array =array('file not exists','file unload');
echo $error_array[$id];
}
}
类的调用方法
$test =new fso_getline();
$test->read_line();
$test->array_to_database();
?>
最后申明一下本站原创转载注明: www.111cn.net/phper/php.html
今天突发奇想, 我在给一客户写一案例时,有一个地方要求网友填写url但是,要保存是正确可访问的,虽然客户没要求但是我们还是想到了这样做,就是用php 的file_get_contents ,ob_get_contents() 来读取远程文章内容,如果有就真否则就假了,下面是我举的两个实例了.关于ob_get_contents() 我们要在php.ini里修改几个地方curl_开头的地方前面的;去了就OK了.
<?php
$url='http://www.111cn.net';
if(@file_get_contents($url)){
echo 'ture';
}else{
echo 'false';
}
if(getcontent($url) ){
echo 'ob_ture';
}else{
echo 'ob_false';
}
function getcontent($url){
$ch =curl_init($url);
ob_start();
curl_exec ($ch);
$retmsg=ob_get_contents();
ob_clean();
ob_end_flush();
curl_close ($ch);
return $retmsg;
}
?>
申明:本站原创文章转载请注明来处 www.111cn.net/phper/php.html