Page 1 of 1

Warning: session_start(): Cannot send session cache limiter

Posted: Thu Jun 29, 2017 7:14 am
by jonnyfortis
let me explain. i have been on forums and followed other peoples solution but to no avail.

i am getting

Code: Select all

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/signfr/public_html/host/signup-login/2017/2017user-progress.php:1) in /home/signfr/public_html/host/signup-login/2017/2017user-progress.php on line 4
amongst other errors but start with this one for now.

as you can see from the script below i have added all the extra code suggested. i have also commented out the session to see if the session was coming from somewhere else but then it was giving me header errors.

code

Code: Select all

<?php //initialize the session
if (!isset($_SESSION)) {
@ob_start();
session_start();
}
require_once('Connections/hostprop.php'); ?>
<?php
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "../../index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php

$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** 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 == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "2017failed-login.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;
}
?>
<?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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE plus_signupComplete SET userprog=%s WHERE userid=%s",
                       GetSQLValueString(isset($_POST['userprog']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['userid'], "text"));

  mysql_select_db($database_hostprop, $hostprop);
  $Result1 = mysql_query($updateSQL, $hostprop) or die(mysql_error());

  $updateGoTo = "2017user-pagenosec.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_hostprop, $hostprop);
$query_Recordset1 = sprintf("SELECT * FROM plus_signupComplete, host_editprop2017 WHERE host_editprop2017.prop_id = plus_signupComplete.prop_id AND plus_signupComplete.userid = %s AND plus_signupComplete.year = 2017", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $hostprop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$status = $row_Recordset1['status'];

// Added by Mike 05.04.2012
// Redirect user if thier application is completed
if($status == "proceed")
{
	header("location: 2017user-pagenosec.php");
}

?>

Re: Warning: session_start(): Cannot send session cache limi

Posted: Thu Jun 29, 2017 9:27 am
by requinix
Make sure you don't have any whitespace before the <?php and that you are saving the PHP file as plain text or UTF-8 without the BOM.

If you don't know about the latter, find yourself a hex editor program online (I use XVI32), open the script, and see if there's anything unexpected before the "<?php" - probably would be an EF BB BF.

Re: Warning: session_start(): Cannot send session cache limi

Posted: Tue Jul 04, 2017 3:01 am
by jonnyfortis
requinix wrote:Make sure you don't have any whitespace before the <?php and that you are saving the PHP file as plain text or UTF-8 without the BOM.

If you don't know about the latter, find yourself a hex editor program online (I use XVI32), open the script, and see if there's anything unexpected before the "<?php" - probably would be an EF BB BF.
ok i will try the hex editor thanks