问候,
我正在使用登录系统,并且卡住Blackberry浏览器进行身份验证.它似乎与PHP的session_regenerate_id()有问题,有人可以提出替代方案吗?以下是auth和登录脚本:
UPDATE
一般来说会议似乎不起作用.拿出session_regenerate_id()只是为了查看它是否可行,它只是每次重定向我,好像$_SESSION [‘MD_SESS_ID’]是空白的.真的卡在这里,任何想法将不胜感激.使用Blackberry Bold 9650启用设备上的Cookie.它适用于我的iPod Touch和PC上的每个浏览器.
登录
<?php
session_start();
include $_SERVER['DOCUMENT_ROOT'] . '/includes/pdo_conn.inc.php';
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return $str;
}
$username = clean($_POST['username']);
$password = clean($_POST['password']);
if ($username != "" && $password != "") {
$getUser = $db->prepare("SELECT id, username, password, salt FROM uc_dev WHERE username = ? LIMIT 1");
$getUser->execute(array($username));
$userDetails = $getUser->fetch();
$dbPW = $userDetails['password'];
$dbSalt = $userDetails['salt'];
$hashedPassword = hash('sha512', $dbSalt . $password);
if ($hashedPassword == $dbPW) {
//Login Successful
session_regenerate_id();
$_SESSION['MD_SESS_ID'] = $userDetails['id'];
header('Location: http://somewhere.com');
session_write_close();
} else {
header('Location: http://www.somewhere.com');
exit();
}
} else {
header('Location: http://somewhere.com');
exit();
}
?>
验证
<?php
//Start the session
session_start();
//Verify that MEMBER ID session is present
if(!isset($_SESSION['MD_SESS_ID']) || (trim($_SESSION['MD_SESS_ID']) == '')) {
$_SESSION = array();
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();
header("Location: http://somewhere.com");
exit();
}
?>
最佳答案 不久前,我正在做一些Blackberry开发,发现浏览器无法处理多个同名的cookie.不知道他们是否已经修好了.
因此,如果您多次发送Set-Cookie标头(使用setcookie,session_start或session_regenerate_id),每次使用相同的名称,这可能会导致您的问题.
您可能希望在对象或数组中跟踪需要输出的cookie,并且只在请求的最后将它们发送到浏览器.这样,如果您需要在请求中间更改其值,则可以覆盖数组的值,而不是发送另一个cookie标头.
This page也可以帮助 – 从PHP的session_regenerate_id页面链接到它的人.