×î¼òµ¥µÄPHP³ÌÐò--¼ÇÊýÆ÷_php»ù´¡_½Å±¾Ö®¼Ò
程序员文章站
2022-04-25 23:33:52
...
ÔÀí£º
1.µÚһλʹÓÃÕßä¯ÀÀijҳ¡£
2.ËÅ·þÆ÷³Ìʽ´Ó×ÊÁÏ¿â»òµµ°¸ÖжÁÈ¡¸ÃÒ³±»ä¯ÀÀ´ÎÊý¡£
3.½«´ÎÊý¼ÓÒ»´¢´æ£¬²¢½«ËüËͻصÚһλʹÓÃÕß¡£
4.µÚ¶þλʹÓÃÕßä¯ÀÀijҳ¡£
5.ËÅ·þÆ÷³Ìʽ´Ó×ÊÁÏ¿â»òµµ°¸ÖжÁÈ¡¸ÃÒ³±»ä¯ÀÀ´ÎÊý¡£
6.½«´ÎÊýÔÙ¼ÓÒ»´¢´æ£¬²¢½«ËüËͻصڶþλʹÓÃÕß¡£
ÐèÒªÁ˽âµÄº¯Êý:
fopen()´ò¿ªÎļþ
filesize()»ñµÃÎļþ´óС
fseek()Òƶ¯ÎļþÖ¸Õë
fgets()µÃµ½ÎļþÖ¸ÕëËùÔÚÐÐÄÚÈÝ
fputs()½«×Ö´®Ð´ÈçÎļþÖ¸ÕëËùÔÚλÖÃ
fclose()¹Ø±ÕÎļþ
file_exists()ÅжÏÎļþÊÇ·ñ´æÔÚ
exec()Ö´ÐÐÍⲿ³ÌÐò
×î¼òµ¥µÄ¼ÇÊýÆ÷:
·Ã¿Í¼ÆÊýÆ÷ ÔÐÍ
/*
(c)1998 David W. Bettis
ÕâÀïÊÇ°æȨÐÅÏ¢
*/
$counterFile = "counter.txt";
#ÕâÀïÊǶ¨Òå¼ÇÊýÆ÷Îļþ
function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");
#´ò¿ªÎļþ£¬ÓöÁд·½Ê½
$num = fgets($fp,5);
#È¡µÃµ±Ç°Êý×Ö
$num += 1;
#¼Ó1
print "ÄúÊÇµÚ "."$num"." λÎÞÁÄ·Ý×Ó";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");
#͵ÀÁµÄ·½Ê½Å¶£¬²»Ê¹ÓÃfputsдÈë
}
if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}#Èç¹û¼ÇÊýÆ÷Îļþ²»´æÔÚ£¬Ð½¨Ëü²¢ÉèÖÃÄÚÈÝΪ0
displayCounter($counterFile);
?>
PHP¼ÇÊýÆ÷±È½Ï¼òµ¥°æ£º
#°æȨûÓÐÀ²£¬Õâô¼òµ¥
$fp=fopen("counter.txt","r+");
flock($fp,3);
#´ò¿ª¼ÇÊýÆ÷Îļþ²¢Ëøס
$fsize=filesize("count.txt");
$count=fgets($fp,$fsize+1);
$count++;
#È¡µÃÊýÂë²¢¼ÓÒ»
fseek($fp,0);
fputs($fp,$count);
fclose($fp);
#½«ÐÂÊýÂëдÈëÎļþ
echo "ÄãÊÇµÚ $count λ·ÃÎÊÕß";
?>
PHP¼ÇÊýÆ÷ͼÐΰ棺
ÖÆ×÷10¸öͼƬ£¬½«Êý×Ö´®ÓÃͼƬ×éÆðÀ´£¬ÎҾͲ»Ï¸ËµÁË
¼ÙÉèͼƬΪ0.gif ~ 9.gif
....$countΪȡµÃµÄÊýÖµ
$strcount=strval($count);
$strcount=chop($strcount);
$countlen=$strlen($strcount);
$shtml="";
for ($i=0; $i$shtml.="";
}
echo $shtml;
?>
PHP¼ÇÊýÆ÷Êý¾Ý¿â°æ£º
ʹÓÃSQL¼ÇÊýÆ÷£¬ÏȽ¨ºÃ±í
CREATE TABLE counter
(
counter int not null,
id ÿÿÿÿÿint not null
)
INSERT INTO counter(counter,id) VALUE(0,1)
$conn=mysql_connect(..., ..., ...);
#MySQLÊý¾Ý¿âÁ¬½Ó
$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 "ÄãÊǵÚ$countλ·Ã¿Í";
?>
1.µÚһλʹÓÃÕßä¯ÀÀijҳ¡£
2.ËÅ·þÆ÷³Ìʽ´Ó×ÊÁÏ¿â»òµµ°¸ÖжÁÈ¡¸ÃÒ³±»ä¯ÀÀ´ÎÊý¡£
3.½«´ÎÊý¼ÓÒ»´¢´æ£¬²¢½«ËüËͻصÚһλʹÓÃÕß¡£
4.µÚ¶þλʹÓÃÕßä¯ÀÀijҳ¡£
5.ËÅ·þÆ÷³Ìʽ´Ó×ÊÁÏ¿â»òµµ°¸ÖжÁÈ¡¸ÃÒ³±»ä¯ÀÀ´ÎÊý¡£
6.½«´ÎÊýÔÙ¼ÓÒ»´¢´æ£¬²¢½«ËüËͻصڶþλʹÓÃÕß¡£
ÐèÒªÁ˽âµÄº¯Êý:
fopen()´ò¿ªÎļþ
filesize()»ñµÃÎļþ´óС
fseek()Òƶ¯ÎļþÖ¸Õë
fgets()µÃµ½ÎļþÖ¸ÕëËùÔÚÐÐÄÚÈÝ
fputs()½«×Ö´®Ð´ÈçÎļþÖ¸ÕëËùÔÚλÖÃ
fclose()¹Ø±ÕÎļþ
file_exists()ÅжÏÎļþÊÇ·ñ´æÔÚ
exec()Ö´ÐÐÍⲿ³ÌÐò
×î¼òµ¥µÄ¼ÇÊýÆ÷:
/*
(c)1998 David W. Bettis
ÕâÀïÊÇ°æȨÐÅÏ¢
*/
$counterFile = "counter.txt";
#ÕâÀïÊǶ¨Òå¼ÇÊýÆ÷Îļþ
function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");
#´ò¿ªÎļþ£¬ÓöÁд·½Ê½
$num = fgets($fp,5);
#È¡µÃµ±Ç°Êý×Ö
$num += 1;
#¼Ó1
print "ÄúÊÇµÚ "."$num"." λÎÞÁÄ·Ý×Ó";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");
#͵ÀÁµÄ·½Ê½Å¶£¬²»Ê¹ÓÃfputsдÈë
}
if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}#Èç¹û¼ÇÊýÆ÷Îļþ²»´æÔÚ£¬Ð½¨Ëü²¢ÉèÖÃÄÚÈÝΪ0
displayCounter($counterFile);
?>
PHP¼ÇÊýÆ÷±È½Ï¼òµ¥°æ£º
#°æȨûÓÐÀ²£¬Õâô¼òµ¥
$fp=fopen("counter.txt","r+");
flock($fp,3);
#´ò¿ª¼ÇÊýÆ÷Îļþ²¢Ëøס
$fsize=filesize("count.txt");
$count=fgets($fp,$fsize+1);
$count++;
#È¡µÃÊýÂë²¢¼ÓÒ»
fseek($fp,0);
fputs($fp,$count);
fclose($fp);
#½«ÐÂÊýÂëдÈëÎļþ
echo "ÄãÊÇµÚ $count λ·ÃÎÊÕß";
?>
PHP¼ÇÊýÆ÷ͼÐΰ棺
ÖÆ×÷10¸öͼƬ£¬½«Êý×Ö´®ÓÃͼƬ×éÆðÀ´£¬ÎҾͲ»Ï¸ËµÁË
¼ÙÉèͼƬΪ0.gif ~ 9.gif
....$countΪȡµÃµÄÊýÖµ
$strcount=strval($count);
$strcount=chop($strcount);
$countlen=$strlen($strcount);
$shtml="";
for ($i=0; $i$shtml.="";
}
echo $shtml;
?>
PHP¼ÇÊýÆ÷Êý¾Ý¿â°æ£º
ʹÓÃSQL¼ÇÊýÆ÷£¬ÏȽ¨ºÃ±í
CREATE TABLE counter
(
counter int not null,
id ÿÿÿÿÿint not null
)
INSERT INTO counter(counter,id) VALUE(0,1)
$conn=mysql_connect(..., ..., ...);
#MySQLÊý¾Ý¿âÁ¬½Ó
$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 "ÄãÊǵÚ$countλ·Ã¿Í";
?>
上一篇: 实例分享jquery实现多级菜单效果
下一篇: 10万张图片,怎么找出相似的两张图片?