Problem running Session start!

Asked

Viewed 856 times

0

Follow the page link with the error: [ http://sistema.spessoa.com.br/ ]

I tried that method: [http://www.add-digital.com.br/blog/warning-session_start-function-session-start-cannot-send-session-cache-limiter-headers-already-sent/]

But it didn’t work!

Follows the code of index.php

<?php
if (!isset($_SESSION)) {
  session_start();
}
?>

<?php require_once('mysql.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;
    }
}

// *** Validate request to login to this site.
// session start old

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

if (isset($_POST['Email'])) {
  $loginUsername=$_POST['Email'];
  $password=$_POST['Senha'];
  $MM_fldUserAuthorization = "NIVEL";
  $MM_redirectLoginSuccess = "restrito.php";
  $MM_redirectLoginFailed = "negado.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mysql, $mysql);

  $LoginRS__query=sprintf("SELECT EMAIL, SENHA FROM CAMPANHA2014 WHERE CODCLIPRINC=%s AND SENHA=%s",
  GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "int")); 

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

  if ($loginFoundUser) {
    $loginStrGroup  = mysql_result($LoginRS,0,'NIVEL');
    $_SESSION["Email"] = $_POST['Email'];
    $_SESSION["senha"] = $_POST['Senha'];

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>:::::: Sou Parceiro, Sou Special ::::::</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<img src="img/backcampanha.jpg" id="back" />
<div align="center">
<img src="img/logocampanha.png" id="logo1" />
<div/>
<div id="form_login">
<h1> Efetue seu Login</h1>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="frml_login">
<input name="Email" type="text" size="4" maxlength="100" placeholder="Código" ></br>
<input name="Senha" type="password" placeholder="Senha">
<input name="botao" style="margin-left:40px; margin-top:20px" type="submit" class="button" value="Login">
</form>
<p> <a href="http://www.spessoa.com.br"><img src="img/close.png" border="0"  style=" float:right; margin:0 20px; padding:0" /></a></p>
</div>
<div align="center">
<img src="img/premios.png" id="logo2" />
<div/>
<div align="center">
<img src="img/logoscampanha.png" id="logo2" />
<div/>
</body>
</html>
  • 2

    Try changing the permissions of the folder tmp for writing. [EDIT 1] Enter the code correctly, not readable here.

3 answers

2


As said in the stacktraces that are leaking on your site:

Warning: session_start() [function.session-start]: open(/var/tmp/sessions/sess_7ekql9e05ss2pnkat0d01bilu4, O_RDWR) failed: No such file or directory (2) in /var/www/html/sistema.spessoa.com.br/web/index.php on line 5

Warning: Unknown: open(/var/tmp/sessions/sess_7ekql9e05ss2pnkat0d01bilu4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/tmp/sessions) in Unknown on line 0

The session is trying to write to a file, but it can’t. According to stacktrace, it is because the file does not exist, but this can also be problems in the permission of the server folders.

I suggest you reinstall PHP or change the folder permissions /var recursively.

1

Solution was to point to a folder and give write permissions and place at the beginning of pages that require session:

    <?php
    if (!isset($_SESSION)) {
    ini_set('session.save_path', '/tmp'); 
    session_start();
    }
    ?>
  • 3

    I suggest changing this directly on php.ini, for the solution to be comprehensive.

0

Tries to put session_start(); in the first line of the file.

<?php
if( !isset($_SESSION) ){ session_start(); }
...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.