/*
我设置登录名和密码和会话变量,如...如果他们不从被保存到下一个页面,一个会话状态变量对大家都没好处,将它..因为它会返回“假“并重定向到登录页面?
*/
代码如下 | 复制代码 |
ob_clean(); ob_start(); //////////// SET COOKIE DIRECTORY if (isset($_SERVER['HTTP_HOST'])) { if(strpos($_SERVER['HTTP_HOST'], ':') != -1){ $domain = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); } else{ $domain = $_SERVER['HTTP_HOST']; } $domain = preg_replace('`^www.`', '', $domain); // Per RFC 2109, cookie domains must contain at least one dot other than the // first. For hosts such as 'localhost', we don't set a cookie domain. if (count(explode('.', $domain)) > 2) { ini_set('session.cookie_domain', $domain); } } //////////// END SET COOKIE DIRECTORY //Start session session_start(); //Include database connection details require_once('config.php'); /////////////ERROR REPORTING . . . COMMENT OUT WHEN GOING LIVE! ///////////////////////////////// //echo ini_get('display_errors'); //if (!ini_get('display_errors')) { // ini_set('display_errors', 1); //} //echo ini_get('display_errors'); ///////////// END OF ERROR REPORTING ///////////////////////////////// //Domain Info used to header redirects $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql教程 server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = strips教程lashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); echo ""; //$extra1 = 'login-form.php'; //header("Location: http://$host$uri/$extra1"); exit; } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($password)."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful /////////////////////////////////////////////// THIS LINE APPEARS TO CAUSE IE7 SOME PROBLEMS!!!!!!! ////////////////////////////////////////// // session_regenerate_id (TRUE); /////////////////////////////////////////////// THIS LINE APPEARS TO CAUSE IE7 SOME PROBLEMS!!!!!!! ////////////////////////////////////////// $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; $_SESSION['SESS_ADDRESS'] = $member['address']; $_SESSION['SESS_CITY'] = $member['city']; $_SESSION['SESS_STATE'] = $member['state']; $_SESSION['SESS_LOGIN'] = $member['login']; $_SESSION['SESS_CAPTAIN'] = $member['captain']; $_SESSION['SESS_TEAM'] = $member['team_name']; $_SESSION['SESS_MANUAL_TEAM'] = $member['manual_team']; session_write_close(); //echo ""; $extra2 = 'member-index.php'; header("Location: http://$host$uri/$extra2"); exit; }else { //Login failed //echo ""; $extra3 = 'login-failed.php'; header("Location: http://$host$uri/$extra3"); exit; } }else { die("Query failed"); } |
//方法二
代码如下 | 复制代码 |
if (isset($_SERVER['HTTP_HOST'])) { if(strpos($_SERVER['HTTP_HOST'], ':') != -1){ $domain = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); } else{ $domain = $_SERVER['HTTP_HOST']; } $domain = preg_replace('`^www.`', '', $domain); // Per RFC 2109, cookie domains must contain at least one dot other than the // first. For hosts such as 'localhost', we don't set a cookie domain. if (count(explode('.', $domain)) > 2) { ini_set('session.cookie_domain', $domain); } } |