2014-11-06 61 views
0

我是PHP的新手,已经尝试了所有内容,并尝试过论坛主题尝试修复此问题,但一周后 - 我觉得我不再接近。适用于本地主机,但不适用于网络服务器.... session_start():无法发送会话缓存限制器 - 已发送头文件

本地主机版本正常工作 - 没问题。然而,当我上传它,它给我看下面的讯息话题:

在session_start():不能发送会话缓存限制器 - 已经发送了头(输出开始/home/idigital123/public_html/index.php:2 )在上线41

这里/home/idigital123/public_html/index.php是代码:

<?php require_once('Connections/idigitalconn.php'); ?> 
<?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; 
} 
} 

mysql_select_db($database_idigitalconn, $idigitalconn); 
$query_Recordset1 = "SELECT login.username, login.password FROM login"; 
$Recordset1 = mysql_query($query_Recordset1, $idigitalconn) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 
?> 
<?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 = ""; 
    $MM_redirectLoginSuccess = "header/KS3Yr7.html"; 
    $MM_redirectLoginFailed = "index.php"; 
    $MM_redirecttoReferrer = false; 
    mysql_select_db($database_idigitalconn, $idigitalconn); 

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

    $LoginRS = mysql_query($LoginRS__query, $idigitalconn) or die(mysql_error()); 
    $loginFoundUser = mysql_num_rows($LoginRS); 
    if ($loginFoundUser) { 
    $loginStrGroup = ""; 

    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']) && false) { 
     $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
    } 
    header("Location: " . $MM_redirectLoginSuccess); 
    } 
    else { 
    header("Location: ". $MM_redirectLoginFailed); 
    } 
} 
?> 
+0

'php.ini'可能存在差异。检查错误报告。 – Mooseman 2014-11-06 18:37:33

回答

2

你需要检查什么是:

if (session_status() == PHP_SESSION_NONE) { 
    session_start(); 
} 

相反的:

if (!isset($_SESSION)) { 
    session_start(); 
} 

而且把它放在你的代码的顶部,@Jay解释。

编辑:在这一部分,你需要一个绝对URL(如documentaton解释说:http://php.net/manual/es/function.header.php

header("Location: " . $file); 

所以将其更改为(或你想要的绝对路径的方式):

header("Location: http://" . $_SERVER["HTTP_HOST"] . "/" . $file); 
+0

尝试了这一点,现在错误消息已变为:Warning:session_start():无法发送会话缓存限制器 - 已在/ home/idigital123中发送的头文件(输出开始于/home/idigital123/public_html/index.php:2) /public_html/index.php在线41 – user3049418 2014-11-06 18:44:24

+0

你是否改变了放在上面的那部分? – 2014-11-06 18:45:43

+0

嗨查尔斯,我再次尝试,并在此页上的评论消失。但是,该页面有一个用户名和登录设施。当我尝试登录时,出现以下错误:警告:session_regenerate_id():无法重新生成会话ID - 已在/home/idigital123/public_html/index.php在线66发送的标头 警告:无法修改标头信息 - 标头已经(在/home/idigital123/public_html/index.php:6开始输出)在/home/idigital123/public_html/index.php在线74 – user3049418 2014-11-06 19:04:28

0

Linux使用\n作为行结束。但是,您的文件正在使用\r\n(窗口行尾)。从服务器向浏览器发送数据时,由于线路结尾不良,会发送一些数据。你可以在白色字符显示编辑器中看到它:enter image description here

将其更改为unix风格,一切都应该正常工作。

+0

嗨Esse,我该如何改变它为unix风格 - 你能建议一位编辑吗? – user3049418 2014-11-06 18:50:05

+0

例如记事本++有这样的选项。如果你有权访问服务器上的ssh,你可以在这里执行:http://stackoverflow.com/questions/16768776/convert-line-endings或下载二进制文件在Windows上执行它:http://stackoverflow.com/问题/ 17579553/windows-command-to-convert-unix -eol-to-windows-eol – Esse 2014-11-06 18:52:08

+0

嗨Esse,我已经下载记事本++,但仍然不知道我在做什么(对不起)..请你进一步解释如何去做你的建议。非常感谢和抱歉! – user3049418 2014-11-06 19:26:20

0

顺便确定您没有附加到源文件的BOM(字节顺序标记)。它会导致出现在输出开头的不需要的字符。

相关问题