Jump to content

session error


AviNahum

Recommended Posts

hey,

i have this code:

<?php

//--------------------------------
// Starting our session
//--------------------------------

session_start();

//--------------------------------
// load database connection
//--------------------------------

require "connect.php";

//--------------------------------
// Make some checks if the admin
// Are loged in
//--------------------------------

if ( ! isset($_SESSION['admin']) || ! isset($_SESSION['name']) )
{
require "login.php";
die();
}

if ( $_SESSION['admin'] != 1 || $_SESSION['name'] == "" )
{
require "login.php";
die();
}

if ( $core->input['act'] == logout )
{
unset($_SESSION['admin']);
unset($_SESSION['name']);
session_destroy();

header('Location: index.php');
}

?>

 

im trying to set a simple session, but i getting this error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7

 

but as you can see i put the session start in the top of the file...

 

any ideas?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/217025-session-error/
Share on other sites

The OUTPUT is on line 1 of that file. Either you have an actual character in the file before the <?php tag or the output is the BOM characters that your editor saved at the start of the file. See the last post in this sticky thread - http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

Link to comment
https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127198
Share on other sites

What is on those lines that the error references in the admin file?

 

Also the last clause (logout) your not exiting the script after that last header call...

 

Rw

 

I believe the code that aviavi has posted is the Admin file.

This is usualy fixed (in my limited experience) by removing all blank lines prior to the entry:

<?php
//--------------------------------
// Starting our session
//--------------------------------
session_start();

//--------------------------------
// load database connection
//--------------------------------
require "connect.php";

 

This would prevent the issue that PFMaBiSmAd was talking about (the possibility of hidden characters)

 

The other possibility is too look at the login.php and make sure it doesn't have any headers, as you have already sent them in the admin file.

 

Link to comment
https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127214
Share on other sites

If the problem are the BOM characters that your editor is placing at the start of the file, the solution is to save the file without the BOM characters. If your programming editor does not have an option to change the file encoding to UTF-8 without BOM or to ANSI encoding, you will need to use a better editor.

Link to comment
https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127476
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.