By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

Session termination issue

P: n/a
Hi,

I'm trying to tweak the logout script on my web projects. When I point
users to a logout.php page containing the session_destroy() function, I
get the "Trying to destroy uninitialized session" error.

Any ideas?

Thanks.

Jun 18 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
TristaSD wrote:
Hi,

I'm trying to tweak the logout script on my web projects. When I point
users to a logout.php page containing the session_destroy() function, I
get the "Trying to destroy uninitialized session" error.


Gets initialized with "session_start"

See the example:
http://www.php.net/manual/en/functio...on-destroy.php

--
/Bent
Jun 18 '06 #2

P: n/a
I tried to follow php.net manual to the best of my ability, but I'm
getting two errors now:

Warning: session_start(): Cannot send session cache limiter - headers
already sent
Warning: Cannot modify header information - headers already sent by

All I want to do is create a login page that starts the session, and a
logout page that destroys the session. I'm having a hell of a time.

Jun 18 '06 #3

P: n/a
Message-ID: <11*********************@f6g2000cwb.googlegroups.c om> from
TristaSD contained the following:
I tried to follow php.net manual to the best of my ability, but I'm
getting two errors now:

Warning: session_start(): Cannot send session cache limiter - headers
already sent
Warning: Cannot modify header information - headers already sent by

All I want to do is create a login page that starts the session, and a
logout page that destroys the session. I'm having a hell of a time.

Logout.php
<?php
session_start();
session_destroy();
header("Location: login.php");
exit;
?>


--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 18 '06 #4

P: n/a
TristaSD wrote:
I tried to follow php.net manual to the best of my ability, but I'm
getting two errors now:

Warning: session_start(): Cannot send session cache limiter - headers
already sent
Warning: Cannot modify header information - headers already sent by
Make sure you don't have any output before calling session_start. Not even a
space or a newline.
All I want to do is create a login page that starts the session, and a
logout page that destroys the session. I'm having a hell of a time.


You'll get there. Just remember that session_start needs to be called in all
pages that uses the session-functions or access the session data.

--
/Bent
Jun 18 '06 #5

P: n/a
TristaSD wrote:
I tried to follow php.net manual to the best of my ability, but I'm
getting two errors now:

Warning: session_start(): Cannot send session cache limiter - headers
already sent
Warning: Cannot modify header information - headers already sent by

All I want to do is create a login page that starts the session, and a
logout page that destroys the session. I'm having a hell of a time.

Post your code. It's the fastest way to get help.

In general, your problem is that some character data (could be as simple
as a blank or carriage-return) is being sent before your session_start().

-david-

Jun 19 '06 #6

P: n/a
Geoff Berrow wrote:
Message-ID: <11*********************@f6g2000cwb.googlegroups.c om> from
TristaSD contained the following:
I tried to follow php.net manual to the best of my ability, but I'm
getting two errors now:

Warning: session_start(): Cannot send session cache limiter - headers
already sent
Warning: Cannot modify header information - headers already sent by

All I want to do is create a login page that starts the session, and a
logout page that destroys the session. I'm having a hell of a time.

Logout.php
<?php
session_start();
session_destroy();
header("Location: login.php");
exit;
?>


My logout is a little more involved:

<?php
require_once('autoload.inc');
require_once('redirect.inc');

session_start();

$sessionName = session_name();
$sessionCookie = session_get_cookie_params();

session_destroy();

setcookie($sessionName, false, $sessionCookie['lifetime'],
$sessionCookie['path'], $sessionCookie['domain'],
$sessionCookie['secure']);

redirect('/ctrl/login.ctrl.php');
?>

-david-

Jun 19 '06 #7

P: n/a
Thanks, all. It seems to work now, but some things are still very odd.
For example, when I go to www.mysite.com/session, I get "session
doesn't exist". When I refresh, however, I get the session id. I get
the session ID when I go to www.mysite.com/session/index.php directly.
Is it a default page issue? Why is the session started when I go to
index.php, but not /session/ ?

Here's the code:

*** index.php ***
<?session_start();?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Session Testing</title>
</head>

<body>
<? echo ($PHPSESSID ? "Session $PHPSESSID exists. You can now <a
href=\"logout.php\">log out</a>." : "Session does not exist."); ?>
</body>
</html>

*** logout.php ***
<?session_start();
session_destroy();
//header("Location: index.php");
echo "Session destroyed.";
exit;?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Session Destrustion</title>
</head>

<body>
</body>
</html>

Jun 20 '06 #8

P: n/a
Many "random" errors on php sessions are caused when tring to read the
same file from two different process (and one has the session's file
locked).
Have you tried closing the session for output (leaving it open only for
reads) with session_write_close()? I solved many session issues witht
this.

PS: I don't remember the exact function name

Jun 21 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.