discuz ¾µäphp¼ÓÃܽâÃܺ¯Êý authcode ½âÎö
¿µÊ¢µÄ authcode º¯Êý¿ÉÒÔ˵¶ÔÖйúµÄPHP½ç×÷³öÁËÖØ´ó¹±Ïס£°üÀ¨¿µÊ¢×Ô¼ºµÄ²úÆ·£¬ÒÔ¼°´ó²¿·ÖÖйúʹÓÃPHPµÄ¹«Ë¾¶¼ÓÃÕâ¸öº¯Êý½øÐмÓÃÜ£¬authcode ÊÇʹÓÃÒì»òÔËËã½øÐмÓÃܺͽâÃÜ¡£
ÔÀíÈçÏ£¬¼ÙÈ磺
¼ÓÃÜ
Ã÷ÎÄ£º1010 1001
Ãܳףº1110 0011
ÃÜÎÄ£º0100 1010
µÃ³öÃÜÎÄ0100 1010£¬½âÃÜÖ®ÐèºÍÃܳ×Òì»òϾͿÉÒÔÁË
½âÃÜ
ÃÜÎÄ£º0100 1010
Ãܳףº1110 0011
Ã÷ÎÄ£º1010 1001
²¢Ã»ÓÐʲô¸ßÉîµÄËã·¨£¬Ãܳ×ÖØÒªÐԺܸߣ¬ËùÒÔ£¬¹Ø¼üÔÚÓÚÔõôÉú³ÉÃܳס£
ÄÇÎÒÃÇÒ»Æð¿´Ï¿µÊ¢µÄauthcodeÔõô×öµÄ°É
1.// ²ÎÊý½âÊÍ
2.// $string£º Ã÷ÎÄ »ò ÃÜÎÄ
3.// $operation£ºDECODE±íʾ½âÃÜ,ÆäËü±íʾ¼ÓÃÜ
4.// $key£º Ãܳ×
5.// $expiry£ºÃÜÎÄÓÐЧÆÚ
6.function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
7. // ¶¯Ì¬Ãܳ׳¤¶È£¬ÏàͬµÄÃ÷ÎÄ»áÉú³É²»Í¬ÃÜÎľÍÊÇÒÀ¿¿¶¯Ì¬Ãܳ×
8. $ckey_length = 4;
9.
10. // Ãܳ×
11. $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
12.
13. // Ãܳ×a»á²ÎÓë¼Ó½âÃÜ
14. $keya = md5(substr($key, 0, 16));
15. // Ãܳ×b»áÓÃÀ´×öÊý¾ÝÍêÕûÐÔÑéÖ¤
16. $keyb = md5(substr($key, 16, 16));
17. // Ãܳ×cÓÃÓڱ仯Éú³ÉµÄÃÜÎÄ
18. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
19. // ²ÎÓëÔËËãµÄÃܳ×
20. $cryptkey = $keya.md5($keya.$keyc);
21. $key_length = strlen($cryptkey);
22. // Ã÷ÎÄ£¬Ç°10λÓÃÀ´±£´æʱ¼ä´Á£¬½âÃÜʱÑéÖ¤Êý¾ÝÓÐЧÐÔ£¬10µ½26λÓÃÀ´±£´æ$keyb(Ãܳ×b)£¬½âÃÜʱ»áͨ¹ýÕâ¸öÃܳ×ÑéÖ¤Êý¾ÝÍêÕûÐÔ
23. // Èç¹ûÊǽâÂëµÄ»°£¬»á´ÓµÚ$ckey_lengthλ¿ªÊ¼£¬ÒòΪÃÜÎÄÇ°$ckey_lengthλ±£´æ ¶¯Ì¬Ãܳף¬ÒÔ±£Ö¤½âÃÜÕýÈ·
24. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
25. $string_length = strlen($string);
26. $result = '';
27. $box = range(0, 255);
28. $rndkey = array();
29. // ²úÉúÃܳײ¾
30. for($i = 0; $i <= 255; $i++) {
31.
Ïà¹ØÎĵµ£º
printf()º¯ÊýÊǸñʽ»¯Êä³öº¯Êý, Ò»°ãÓÃÓÚÏò±ê×¼Êä³öÉ豸°´¹æ¶¨¸ñʽÊä³öÐÅÏ¢¡£ÔÚ±àд³ÌÐòʱ¾³£»áÓõ½´Ëº¯Êý¡£º¯ÊýµÄÔÐÍΪ£º
int printf(string $fromat [,mixed $args [,mixed ...]])
º¯Êý·µ»ØֵΪÕûÐÍ¡£Èô³É¹¦Ôò·µ»ØÊä³öµÄ×Ö·ûÊý£¬Êä³ö³ö´íÔò·µ»Ø¸ºÖµ¡£
printf()º¯ÊýµÄµ÷ÓøñʽΪ:
printf("<¸ñʽ»¯×Ö·û´®>", & ......
Ò»¡¢PHP SESSIONÔÀí
ÎÒÃÇÖªµÀ£¬sessionÊÇÔÚ·þÎñÆ÷¶Ë±£³ÖÓû§»á»°Êý¾ÝµÄÒ»ÖÖ·½·¨£¬¶ÔÓ¦µÄcookieÊÇÔÚ¿Í»§¶Ë±£³ÖÓû§Êý¾Ý¡£HTTPÐÒéÊÇÒ»ÖÖÎÞ״̬ÐÒ飬·þ
ÎñÆ÷ÏìÓ¦ÍêÖ®ºó¾ÍʧȥÁËÓëä¯ÀÀÆ÷µÄÁªÏµ£¬×îÔ磬Netscape½«cookieÒýÈëä¯ÀÀÆ÷£¬Ê¹µÃÊý¾Ý¿ÉÒÔ¿Í»§¶Ë¿çÒ³Ãæ½»»»£¬ÄÇô·þÎñÆ÷ÊÇÈçºÎ¼ÇסÖÚ¶àÓû§
µÄ»á»°Êý¾ÝÄØ£¿
Ê×ÏÈÒª ......
conn.php
<?php
/*
* Created on 2010-1-6
* Author:CHAUVET
* Function:Á¬½Ó×Ö·û´®
*/
$conn=@mysql_connect("localhost","root","")or die("Á¬½ÓÊý¾Ý¿â³ö´í£¡");
mysql_select_db("newdb",$conn);
mysql_query("set names 'gb2312'");
function ReplaceSom ......
·¢±íÓÚ2008Äê10ÔÂ14ÈÕ
PHP»ù´¡£º±êǩʹÓãº
PHP´úÂë±ØÐë°üº¬ÔÚ <?PHP ºÍ ?>Ö®¼ä¡£
һЩÆäËûµÄ±êÇ©ÑùʽҲ¿ÉÒÔʹÓ㬱ÈÈç<?,<%,»òÕß<script language="php">(Js±êÇ©)¡£
ÆäËû±êÇ©¿ÉÒÔÊÇÓ㬵«Ö»ÓÐÔÚ<?php £¿>Ö®¼äµÄ½Å±¾²ÅÊÇ¿ÉÓõÄPHP´úÂë¡£
£¨¹ØÓÚlesson 23 µÄphp.iniÅäÖÃÎļþ£©
¿ªÊ ......