SESSION

I’m getting this error

session_regenerate_id(): Cannot regenerate session id - headers already sent

here is the code issue:
[php]session_name(‘CSID’);
@session_start();
if(!isset($_SESSION[‘started’])) {
session_regenerate_id();
$_SESSION[‘started’] = true;
}
ob_start();[/php]

First, get rid of the @ error suppressor and never use it again. Errors are you friend. They tell you when something is wrong.

As far as the error message, you cannot have any output before calling session_regenerate_id including whitespace.

Can you explain? I didn’t understand what you are getting at.

Check for a space…

I have seen this cause a problem:

[php]<?php

session_start();
?>[php]

Also is there anything echo’ing or printing on the screen before that code is being called? Can you supply a webpage so we can see it in action?

That was the first thing I thought of. And I’ve even seen some cPanel editors not show the whitespace, so I hit delete/backspace a few times to make sure.

And, there is no web page to show this error. It’s part of a cron job. So it is just more or less blowing up my error logs. But the cron job is still working.

Hmmm, CLI (cron job) doesn’t have a session… So actually I am not sure why that is in there. Are you sure that you need to create a session for a cron job?

It’s not my script. It is using single file for a global ‘not logged in’ but still pulls the globals for things like the login etc.

What you are posting doesn’t make sense. If this is a Cron job there are no sessions and there are no logins.

Trust me that much I know.

But the file producing the error is a global file. Let’s call it notauthorized.php. A total of 6 files call on notauthorized.php to pull a global functions file for database operations. 4 cron jobs and the login.php and register.php pages.

Because login.php and register.php call on this file, it needs a session. So every time the notauthorized.php file is used it creates a session. It just so happens that the 4 cron jobs also use notauthorized.php to use the database features.

So the option is there to create a new file just for the cron jobs to access the database features, but it would still leave login.php and register.php calling on the notauthorized.php file creating the errors. Hence the session being used.

I would do something like this then:

[php]if (php_sapi_name() == “cli”) {
// In cli-mode
} else {
// Not in cli-mode
}[/php]

in cli mode, put the stuff you need, else put the session stuff

Best thing to do is post a zip file of your scripts so we can see what you’re working with. You can also p.m. it to me if you don’t want it public

Will do Kevin.

[member=46186]Kevin Rubio[/member] have you had a chance to look at the files yet?

Sponsor our Newsletter | Privacy Policy | Terms of Service