当前位置: 编程技术>php
本页文章导读:
▪分享一个PHP数据流应用的简单例子
代码如下: <?php $count = 5; start: if($count < 5) echo "You can try {$count} time, "; echo "Put Password: "; $handle = fopen ("php://stdin","r"); $line = fgets($handle); if(trim($line) != '123456'){ $count--; if(!$count) goto error; goto s.........
▪检查php文件中是否含有bom的函数
代码如下: <?php /*检测并清除BOM*/ if(isset($_GET['dir'])){ $basedir=$_GET['dir']; }else{ $basedir = '.'; } $auto = 1; checkdir($basedir); function checkdir($basedir){ if($dh = opendir($basedir)){ while(($file = readdir($dh)) !== false){ .........
▪php注销代码(session注销)
代码如下: <a href="/blog_article/logout.html" >注销</a> <?php session_start(); session_destroy(); header("location:index.php"); ?>
......
[1]分享一个PHP数据流应用的简单例子
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
$count = 5;
start:
if($count < 5) echo "You can try {$count} time, ";
echo "Put Password: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != '123456'){
$count--;
if(!$count) goto error;
goto start;
}
goto success;
error:
echo "Please try after 1 hour! http://www.";
goto out;
success:
echo "Logined!";
out:
?>
效果图:
[2]检查php文件中是否含有bom的函数
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
/*检测并清除BOM*/
if(isset($_GET['dir'])){
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if($dh = opendir($basedir)){
while(($file = readdir($dh)) !== false){
if($file != '.' && $file != '..'){
if(!is_dir($basedir."/".$file)){
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}//end while
closedir($dh);
}//end if($dh
}//end function
function checkBOM($filename){
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if(ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191){
if($auto == 1){
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return "<font color=red>BOM found, automatically removed.</font>";
}else{
return ("<font color=red>BOM found.</font>");
}
} www.
else return ("BOM Not Found.");
}//end function
function rewrite($filename, $data){
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}//end function
?>
[3]php注销代码(session注销)
来源: 互联网 发布时间: 2013-11-30
代码如下:
<a href="/blog_article/logout.html" >注销</a>
<?php
session_start();
session_destroy();
header("location:index.php");
?>
最新技术文章: