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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.