×î¼òµ¥µÄPHP³ÌĞò--¼ÇÊıÆ÷

5年以前  |  阅读数:1095 次  |  编程语言:PHP 

Ô­Ài£º
1.µÚһλʹÓÃÕßa¯ÀÀijҳ¡£
2.ËÅşÆ÷³Ìʽ´Ó×ÊÁÏ¿a»oµµ°¸ÖжÁÈ¡¸ÃÒ³±»a¯ÀÀ´ÎÊı¡£
3.½«´ÎÊı¼ÓÒ»´¢´ae£¬²¢½«ËuËͻصÚһλʹÓÃÕß¡£
4.µÚ¶şÎ»Ê¹ÓÃÕßa¯ÀÀijҳ¡£
5.ËÅ
şÆ÷³Ìʽ´Ó×ÊÁÏ¿a»oµµ°¸ÖжÁÈ¡¸ÃÒ³±»a¯ÀÀ´ÎÊı¡£
6.½«´ÎÊıÔÙ¼ÓÒ»´¢´ae£¬²¢½«ËuËͻصڶşÎ»Ê¹ÓÃÕß¡£
ĞeÒªÁ˽aµÄº¯Êı:
fopen()´o¿ªÎļş
filesize()»ñµÃÎļş´oĞ¡
fseek()Òƶ¯ÎļşÖ¸Õe
fgets()µÃµ½ÎļşÖ¸ÕeËuÔÚĞĞÄÚÈİ
fputs()½«×Ö´®Ğ´ÈçÎļşÖ¸ÕeËuÔÚλÖÃ
fclose()¹Ø±ÕÎļş
file_exists()ÅжÏÎļşÊÇ*ñ´aeÔÚ
exec()Ö´ĞĞÍa²¿³ÌĞo

×i¼oµ¥µÄ¼ÇÊıÆ÷:

*ÿͼÆÊıÆ÷ Ô­ĞÍ $counterFile = "counter.txt";

ÕaÀiÊǶ¨Òa¼ÇÊıÆ÷Îļş

function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");

´o¿ªÎļş£¬ÓöÁĞ´*½Ê½

$num = fgets($fp,5);

È¡µÃµ±Ç°Êı×Ö

$num += 1;

¼Ó1

print "ÄuÊÇµÚ "."$num"." λΪÁÄ*İ×Ó";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");

͵ÀÁµÄ*½Ê½Å¶£¬²»Ê¹ÓÃfputsĞ´Èe

}

if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}#Èç¹u¼ÇÊıÆ÷Îļş²»´aeÔÚ£¬Ğ½¨Ëu²¢ÉeÖÃÄÚÈİΪ0

displayCounter($counterFile);

?>

PHP¼ÇÊıÆ÷±È½Ï¼oµ¥°ae£º $fp=fopen("counter.txt","r+");
flock($fp,3);

´o¿ª¼ÇÊıÆ÷Îļş²¢Ëøס

$fsize=filesize("count.txt");
$count=fgets($fp,$fsize+1);
$count++;

È¡µÃÊıÂe²¢¼ÓÒ»

fseek($fp,0);
fputs($fp,$count);
fclose($fp);

½«ĞÂÊıÂeĞ´ÈeÎļş

echo "ÄaÊÇµÚ $count λ*ÃÎÊÕß";
?>

PHP¼ÇÊıÆ÷ͼĞΰae£º
ÖÆ×÷10¸oͼƬ£¬½«Êı×Ö´®ÓÃͼƬ×eÆğÀ´£¬ÎҾͲ»Ï¸ËµÁË
¼ÙÉeͼƬΪ0.gif ~ 9.gif

<?
....$countΪȡµÃµÄÊıÖµ
$strcount=strval($count);
$strcount=chop($strcount);
$countlen=$strlen($strcount);
$shtml="";
for ($i=0; $i<$countlen; $i++) {
$shtml.="";
}
echo $shtml;
?>

PHP¼ÇÊıÆ÷Êı¾İ¿a°ae£º
ʹÓÃSQL¼ÇÊıÆ÷£¬ÏȽ¨ºÃ±i
CREATE TABLE counter
(
counter int not null,
id ÿÿÿÿÿint not null
)
INSERT INTO counter(counter,id) VALUE(0,1)

<?
$conn=mysql_connect(..., ..., ...);

MySQLÊı¾İ¿aÁ¬½Ó

$sql="select * from counter";
$result=mysql_query($sql,$conn);
$objresult=mysql_fetch_object($result);
$count=$objresult->counter;
$count++;

$sql="update counter set counter=".$count."where id=1";
mysql_query($sql,$conn);
mysql_close($conn);

echo "ÄaÊǵÚ$countλ*ÿÍ";
?>

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例