Php Dreamweaver CS6登录服务器行为在生产服务器上不起作用

Php Dreamweaver CS6登录服务器行为在生产服务器上不起作用,php,session,dreamweaver,Php,Session,Dreamweaver,非常感谢你的阅读。 我使用DW CS 6.0生成的以下代码——登录用户ServerBehavior——开发了一个有密码保护的站点,其中包含两个用户组,即用户组和管理员组。该站点仅用于演示目的,因为DW生成的PHP-MYSQL代码已经过时-没有PDO或MySQLi 数据库连接代码: $hostname_imerida = "xxxxx"; $database_imerida = "xxxxx"; $username_imerida = "xxxxx"; $password_imerida = "x

非常感谢你的阅读。 我使用DW CS 6.0生成的以下代码——登录用户ServerBehavior——开发了一个有密码保护的站点,其中包含两个用户组,即用户组和管理员组。该站点仅用于演示目的,因为DW生成的PHP-MYSQL代码已经过时-没有PDO或MySQLi

数据库连接代码:

$hostname_imerida = "xxxxx";
$database_imerida = "xxxxx";
$username_imerida = "xxxxx";
$password_imerida = "xxxxx";
$imerida = mysql_pconnect($hostname_imerida, $username_imerida, $password_imerida) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_set_charset('utf8',$imerida);
date_default_timezone_set('Europe/Athens');`  
如果凭据正确,DW生成的登录到站点的代码:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();

}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "role";
  $MM_redirectLoginSuccess = "managepub.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_imerida, $imerida);

  $LoginRS__query=sprintf("SELECT username, password, role FROM users WHERE username=%s AND password=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $imerida) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);


  if ($loginFoundUser) {

    $loginStrGroup  = mysql_result($LoginRS,0,'role');

    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
   $_SESSION['MM_Username'] = $loginUsername;
   $_SESSION['MM_UserGroup'] = $loginStrGroup;  

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
实验表明,如果我将 如果PHP_VERSION>=5.1{session_regenerate_idtrue;}否则{session_regenerate_id;} 生产服务器中的问题得到了缓解,而且很少发生。这为我指明了 服务器中的会话处理有问题,但我无法想出下一步应该做什么,或者为什么会发生这种情况

请分享你的想法


非常感谢。

我建议在Chrome中调试网络头F12,看看问题出在哪里

在生产服务器上,似乎偶尔会有来自服务器的奇怪重定向响应


我建议查看Apache配置文件。在OP的情况下,托管提供商负责Apache配置。OP联系了主机提供商并解决了他的问题。托管提供商的会话管理出现问题。

您可以通过调试网络头(例如,使用Chrome F12tanks作为提示)来查找会话cookie何时更改以及更改原因。我将使用firebug,但我不完全了解此信息如何帮助我解决问题。例如,未设置cookie,因为在设置cookie之前发送了一些信息。在这种情况下,您将找不到cookie标头。或者cookie在不应该重置的情况下被重置。再次感谢Keiv.fly,但是如果在标头之前发送了某些内容(例如空格字符等),那么在本地主机和生产环境中不应该发生此问题吗?因为脚本是相同的?尽管问题是来自托管提供商,我接受了这个答案,因为keiv.fly的有用评论指向了一个正确的方向。
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 

  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);

  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?> 
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);

  header("Location: ". $MM_restrictGoTo);