PHP session_regenerate_id 和黑莓浏览器

发布于 2024-10-10 05:24:32 字数 2124 浏览 0 评论 0原文

您好,

我正在开发一个登录系统,并陷入了黑莓浏览器身份验证的困境。他们似乎对 PHP 的 session_regenerate_id() 有问题,有人可以建议替代方案吗?以下是身份验证和登录脚本:

更新 看来会话一般都不起作用。拿出 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();
 }
?>

Greetings,

I am working on a login system and getting stuck with Blackberry browsers authenticating. It seems they have an issue with PHP's session_regenerate_id(), can someone suggest an alternative? Here are the auth and login scripts:

UPDATE
It would appear that sessions in general are not working. Took out session_regenerate_id() just to see if it would work and it just redirects me every time, as though the $_SESSION['MD_SESS_ID']were blank. Really stuck here, any ideas would be appreciated. Cookies on the device are enabled, using a Blackberry Bold 9650. It works on my iPod Touch and every browser on my PC.

Login

<?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();
}
?>

Auth

<?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();
 }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我喜欢麦丽素 2024-10-17 05:24:32

前一段时间,我在做一些Blackberry开发,发现浏览器无法处理多个同名的cookie。不确定他们是否已经解决了这个问题。

因此,如果您多次发送 Set-Cookie 标头(使用 setcookiesession_startsession_regenerate_id),每次使用相同的名称,这可能会导致您的问题。

您可能希望在对象或数组中跟踪需要输出的 cookie,并仅在请求最后将它们发送到浏览器。这样,如果您需要在请求中间更改它们的值,您可以覆盖数组的值,而不是发送另一个 cookie 标头。

此页面可能会也有帮助——有人从 PHP 的 session_regenerate_id 页面链接到它。

A while ago, I was doing some Blackberry development, and found out that the browser couldn't handle multiple cookies with the same name. Not sure if they've fixed this yet.

So if you're sending out the Set-Cookie header more than once (using setcookie, session_start, or session_regenerate_id), using the same name each time, this could be causing your problem.

You might want to keep track of the cookies you need to output, in an object or array, and only send them to the browser at the very end of the request. This way, if you need to change their values in the middle of the request, you can just overwrite the array's value, rather than sending out another cookie header.

This page may also help -- someone linked to it from PHP's session_regenerate_id page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文