ÕâÁ½ÌìÊÜÅóÓѵÄÍи¶£¬ÒªÎÒ°ïËûдһ¸öʹÓÃMySQLÊý¾Ý¿âµÄÓû§ÈÏ֤ϵͳ¡£ÎÒµ±È»²»ºÃÍÆÍѵģ¬Ö»µÃºÄ·ÑÁËÒ»ÍíÉϵÄÐÝϢʱ¼ä£¬Ð´Á˸öºÜ¼òµ¥µÄPHP³ÌÐò¡£ÓÉÓڸϵĺܲÖ×䣬¿ÉÄÜ»áÌ«¼òªÁËЩ£¬¶øÇÒ¿ÉÄÜ»¹»áÓдíÎóºÍ©¶´¡£ÓÐÐËȤ¿´¿´µÄÅóÓÑÈç¹ûÓÐʲô¸üºÃµÄ·½·¨»ò½¨Ò飬ÇëemailÎÒ.ÔÚÕâ¶ùÏÈллÁË£¡
??Óû§ÈÏÖ¤µÄÔÀíºÜ¼òµ¥£ºÊ×ÏÈÐèÒªÓû§ÔÚÒ³ÃæÉÏÌîÈëÓû§ÃûºÍÃÜÂ룬µ±È»Ã»×¢²áµÄÓû§ÐèÒªÏÈ×¢²á¡£È»ºóµ÷ÓÃÊý¾Ý¿âËÑË÷ÊÇ·ñÓÐÏàÓ¦µÄÓû§¡£Èç¹ûÓоÍÈ·ÈÏ£¬Ã»ÓÐÔòÌáÐÑÓû§ÏÈ×¢²á¡£Ê¹ÓÃPHPÀ´Íê³ÉÕâÒ»Çкܼòµ¥£¬µ«ÐèҪעÒâµÄÊÇÈç¹ûÏëÔÚÒÔºóµÄÒ³ÃæÖж¼ÄÜÈ·ÈÏÓû§Éí·Ý£¬Ê¹ÓÃPHP3ÎÒÖ»ÄÜÏë³öʹÓÃcookieµÄ·½·¨¡£ÒªÏëʹÓÃsession,¾ÍÖ»ÄܵȴýPHP4Õýʽ°æµÄ·¢²¼ÁË£¡
??µÚÒ»²½ÊÇ×öÒ»¸öµÇ¼µÄÒ³Ã棬Õâ¶ù¾Í²»¶à½²ÁË¡£ÎÒÖ»×öÁ˸ö¼«¼òµ¥µÄ£¬´ó¼Ò×Ô¼º×öµÃƯÁÁµã¡£
??µÚ¶þ²½¿ªÊ¼µÇ¼ºóµÄÈ·ÈϳÌÐòµÄÉè¼Æ¡£
??login.php:?
mysql_connect("localhost","user","password") /*Á¬½ÓÊý¾Ý¿â£¬Óû§ÃûºÍÃÜÂë×ÔÐÐÐÞ¸Ä*/
or die("ÎÞ·¨Á¬½ÓÊý¾Ý¿â£¬ÇëÖØÊÔ");
mysql_select_db("userinfo")
or die("ÎÞ·¨Ñ¡ÔñÊý¾Ý¿â£¬ÇëÖØÊÔ");
$today=date("Y-m-d H:i:s");
$query="
select id
from usertbl
where name=$name and password=$password /*´ÓÊý¾Ý¿âÖÐËÑË÷ºÍµÇ¼Óû§ÏàÓ¦µÄ×ÊÁÏ*/
";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
if($numrows==0){ /*ÑéÖ¤ÊÇ·ñÄÜÕÒ³öÏàͬ×ÊÁϵÄÓû§£¬²»ÄÜÔòδע²á*/
echo ·Ç·¨Óû§
;
echo Çë×¢²áÏÈ
;
echo ÖØÊÔ
;
}
else{
$row=mysql_fetch_array($result);
$id=$row[0];
$query="
update usertbl
set lastlogin=$today
where id=$id";
$result=mysql_query($query);
SetCookie("usercookie", "»¶ÓÄã,$name"); /*ÕâÀïʹÓÃÁËcookie£¬ÒÔ·½±ãÖ®ºóµÄÒ³ÃæÈÏÖ¤¡£µ«ÎÒ먦·¢ÍêÕâÒ»¿é¡£Ï£ÍûÓÐÐËȤµÄÅóÓÑÖ¸Õý*/
echo µÇ¼³É¹¦
;
echo Çë½ø£¡
;
}
?>
µÚÈý²½µ±È»ÊÇ×öºÃ×¢²áµÄÒ³Ã棬Ҳ²»¶à½²ÁË:
µÚËIJ½ÊÇ×¢²áºóµÄÉí·ÝÈ·ÈϺÍÊäÈëÊý¾Ý¿â¡£
??register.php:
mysql_connect("localhost","user","password") /*ÇëÐÞ¸ÄÓû§ÃûºÍÃÜÂë*/
or die("ÎÞ·¨Á¬½ÓÊý¾Ý¿â£¬ÇëÖØÊÔ");
mysql_select_db("userinfo")
or die("ÎÞ·¨Ñ¡ÔñÊý¾Ý¿â£¬ÇëÖØÊÔ");
$query="select id from usertbl where name=$name\"; /*´ÓÊý¾Ý¿âÖÐËÑË÷ÏàͬÃû×ÖµÄÓû§×ÊÁÏ*/
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
if($numrows!=0) /*ÕÒµ½Á˵±È»¾ÍÊÇÓÐÈËÏÈ×¢²áÁËÏàͬµÄÃû×Ö*/
{echo ÒÑÓÐÈË×¢²á´ËÃû£¬ÇëÖØÐÂÑ¡ÔñÃû×Ö!;}
else
{$query="insert into usertbl values(0,$name,$password,\)"; /*ÕÒ²»µ½ÏàͬµÄ¾ÍÊäÈëеÄÓû§×ÊÁÏ*/
mysql_query($query);
echo ×¢²á³É¹¦;
echo ÇëµÇ¼!;}
?>
ÏÂÒ»²½ÊÇcookieµÄʹÓã¬ÎÒÔ´òËãʹÓÃcookieÀ´Ê¹Ã¿Ò»Ò³¶¼ÄÜʶ±ðÓû§Éí·Ý£¬µ«ÓÉÓÚ±ðµÄÒ³Ã滹û×öºÃ£¬²»ÖªµÀÐèÒªÓõ½ÄÄЩ×ÊÁÏ¡£ÓÚÊǾÍÖ»ÓÐÒ»¸öºÜ¼òµ¥µÄʹÓã¬ÕâÀïÓõ½ÁËphpµÄÒýÓÃ:
if(!$usercookie)
{header("·Ç·¨Óû§");
}
?>
welcome.php:
require("cookie.php"); /*µ÷ÓÃcookie.php*/
?>
echo $usercookie;
?>
µ½Õâ¶ù±ãÍê³ÉÁËÒ»¸öºÜ¼òµ¥µÄÓû§ÈÏ֤ϵͳ£¬µ±È»Èç¹ûÄãҪʹÓÃËü»¹µÃ½¨ºÃÊý¾Ý¿â.ÏÂÃæÊÇÎÒµÄÊý¾Ý¿â±íµÄ½á¹¹,¿âµÄÃû×ÖÊÇuserinfo.
create table usertbl
(
ID int auto_increment primary key,
Name varchar(30),
Password varchar(20),
Lastlogin varchar(20)
);
Ô×÷Õߣºrobbin À´Ô´£ºPHPÖ®ÐÇ
8g ÓÚ 2005-11-14 00:30:23·¢±í:
²»´í£¬Ö§³Ö
ÐǹâÒÀÈ» ÓÚ 2005-10-12 00:39:36·¢±í:
²»´í
ÐÂРÓÚ 2005-08-05 00:20:26·¢±í:
Ö§³Ö
»ð ÓÚ 2005-07-03 13:09:20·¢±í:
Ö§³Ö