0

This will probably be put down as a 'Duplicate' but I have read the top posts concerning this problem as sadly putting

session_start();

At the top didn't seem to work for me as that was the most suggested answer.

In addition to this, I uploaded this to my Website about 20 - 30 minutes ago but it was working fine with Xammp, probably different PHP versions.

Here is my code and the errors:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 33

Code:

<?php 
session_start();


include('config.php');

$user_check = $_SESSION['login_user'];

$ses_sql = mysqli_query($db,"select * from users where email = '$user_check' ");

$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$login_id = $row['id'];
$login_session = $row['email'];
$login_password = $row['password'];
$rank = $row['rank']; 
$join_date = $row['joined'];    
$bio = $row['bio'];
$credits = $row['credits'];
$adminlevel = $row['adminlevel'];
$banned = $row['banned'];

//Get stats
$ses_sql = mysqli_query($db,"select * from stats");

$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$sales = $row['sales'];
$members = $row['members'];
$vip = $row['vips'];

if(!isset($_SESSION['login_user'])){
   header("location: login.php");
}

?>

  • Do you ever end the session? My guess is you never end the session and then try to reconnect and start a new session, because the session never ended you can't ever start a new one. – Hunter Oct 07 '17 at 13:57
  • The session ends when you log out. – Samuel Stubbings Oct 07 '17 at 13:58
  • https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php Apparently this is a common php problem – Hunter Oct 07 '17 at 14:05
  • session_start([ 'cookie_lifetime' => 86400, 'read_and_close' => true, ]); And this link should help http://php.net/manual/en/reserved.variables.session.php – Hunter Oct 07 '17 at 14:23
  • Warning says that "output started at `index.php` line 29 can you also share the `index.php` (I'm assuming this file is the `session.php` ) – apokryfos Oct 07 '17 at 14:55

1 Answers1

0

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 2

The error clearly stated the problem

(output started at /home/corrupts/public_html/index.php:29)

Header sent out already at line 29 of your index.php (you already start a session inside your index.php) Which is probably the same code at line 2 of session.php. /home/corrupts/public_html/pages/examples/session.php

NOTE: It's better to check if the session already exists, use the same session rather than re-creating another session. You can do that by adding the following code to top of your page where session is required.

if( empty( session_id() ) )
{
   session_start();
)

Hope it helps!

Prince Adeyemi
  • 724
  • 6
  • 12
  • I rewrote some stuff and there is only one session_start(); Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/corrupts/public_html/index.php:35) in /home/corrupts/public_html/steamauth/steamauth.php on line 3 – Samuel Stubbings Oct 15 '17 at 15:42