转自:http://www.nowamagic.net/librarys/veda/detail/2076
ini_set(‘error_reporting‘, E_ALL | E_STRICT); ini_set(‘display_errors‘, ‘Off‘); ini_set(‘log_errors‘, ‘On‘); ini_set(‘error_log‘, ‘/usr/local/apache/logs/error_log‘);
或者设置错误处理函数:
set_error_handler(‘my_error_handler‘);
function my_error_handler($number, $string, $file, $line, $context) { $error = "= == == == ==\nPHP ERROR\n= == == == ==\n"; $error .= "Number: [$number]\n"; $error .= "String: [$string]\n"; $error .= "File: [$file]\n"; $error .= "Line: [$line]\n"; $error .= "Context:\n" . print_r($context, TRUE) . "\n\n"; error_log($error, 3, ‘/usr/local/apache/logs/error_log‘); }
$salt = ‘SHIFLETT‘; $identifier = md5($salt . md5($username . $salt)); $token = md5(uniqid(rand(), TRUE)); $timeout = time() + 60 * 60 * 24 * 7; setcookie(‘auth‘, "$identifier:$token", $timeout);
2)验证
$clean = array(); $mysql = array(); $now = time(); $salt = ‘SHIFLETT‘; list($identifier, $token) = explode(‘:‘, $_COOKIE[‘auth‘]); if (ctype_alnum($identifier) && ctype_alnum($token)) { $clean[‘identifier‘] = $identifier; $clean[‘token‘] = $token; } else { /* ... */ } $mysql[‘identifier‘] = mysql_real_escape_string($clean[‘identifier‘]); $sql = "SELECT username, token, timeout FROM users WHERE identifier = ‘{$mysql[‘identifier‘]}‘"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); if ($clean[‘token‘] != $record[‘token‘]) { /* Failed Login (wrong token) */ } elseif ($now > $record[‘timeout‘]) { /* Failed Login (timeout) */ } elseif ($clean[‘identifier‘] != md5($salt . md5($record[‘username‘] . $salt))) { /* Failed Login (invalid identifier) */ } else { /* Successful Login */ } } else { /* Failed Login (invalid identifier) */ } } else { /* Error */ }
setcookie(‘auth‘, ‘DELETED!‘, time());
原文:http://www.cnblogs.com/fuland/p/4293142.html