常用的模块

验证码的学习

 

验证码 文件,其实就是一个php写成的生成图片的文件acthcode.php,

在需要的时候,

<input type="text" name="authcode"/>&nbsp;<img src="authcode.php" alt="看不清?点击更换" align="absmiddle" onclick="this.src+='?'+Math.random()"/>

直接引用就可以实现,在服务器的地方,使用if($_POST['authcode'] = $_SESSION['authcode'])完成对验证码的判断

 

 

后台频道的判断

admin.php?action=content 后台的内容管理模块

admin.php?action=content&do=content_list 内容管理中的内容列表模块

admin.php?action=content&do=content_list$content_id=3 内容列表中的id=3的新闻内容

 

 

 

获得指定目录下的各个文件以及统计文件数量

 

function getdir($dir){

 

$dir =empty($dir)?getcwd():$dir;

$dir_list = scandir($dir,1);

echo count($dir_list)."<hr>";

foreach($dir_list as $k=>$v){

echo $k."=>".$v."<br>";

 

}

 

}

随机向某段字符串插入一字符串:

思路先把$str随即分割开,分别取得这个分割点前后两个zifuc

然后再和$substr 使用.合成

function str_insert($str, $i, $substr)

{

$str= "abcdefghijklmnopqrstuvwxyz";

$substr = "2222";

$i = mt_rand(1,26);

 

for($j=0; $j<$i; $j++){

$startstr .= $str[$j];

}

 

for ($j=$i; $j<strlen($str); $j++){

$laststr .= $str[$j];

}

 

$str = ($startstr . $substr . $laststr);

return $str;

}

计算页面加载运行了多久时间

<?php

 

$pagestartime=microtime();

 

?>

<!--网页内容开始-->

<html>

<head>

<title>php计算页面打开时间</title>

</head>

<body>

我要IT网页面打开的好快呀!

</body>

</html>

<!--网页内容结束-->

<?php

$pageendtime = microtime();

$starttime = explode(" ",$pagestartime);

$endtime = explode(" ",$pageendtime);

$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];

$timecost = sprintf("%s",$totaltime);

echo "页面运行时间: $timecost 秒";

?>

 

 

PHP获取客户端真实 IP 地址

该函数将获取用户的真实 IP 地址,即便他使用代理服务器。

 

function getRealIpAddr()

{

if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))

{

$ip=$_SERVER['HTTP_CLIENT_IP'];

}

elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR']))

//to check ip is pass from proxy

{

$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];

}

else

{

$ip=$_SERVER['REMOTE_ADDR'];

}

return $ip;

}

 

 

 

11. PHP强制性文件下载

为用户提供强制性的文件下载功能。

 

function force_download($file)

{

if ((isset($file))&&(file_exists($file))) {

header("Content-length: ".filesize($file));

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename="' . $file . '"');

readfile("$file");

} else {

echo "No file selected";

}

}

 

 

./表示当前文件同级目录下面的东西,../表示上级目录里面的东西。

posted @ 2011-04-26 05:40  y0umer  阅读(152)  评论(0编辑  收藏  举报