473,480 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

session_destroy()

Ken
I am curious how others solve this problem.

After storing the data from sessions in the database. How do you handle the
session data stored on the server and cookie on the users computer.

I know how to destroy the session data and remove the cookie, but how do you
handle this problem.

I see three possibilities:

1. Do not remove the session data and cookie Security concerns?
2. Remove the cookie, but not the session data Endless storage of useless
data on the server
3. Remove the session data and cookie
The problem with item #3, if you destroy the session data after
displaying the data on the users screen, and then the user refreshes the
page, he sees a blank page.


Jul 17 '05 #1
7 2248
Ken wrote:

Hi Ken,

Can you clarify your problem a bit more?
I am confused. :-)
I am curious how others solve this problem.

After storing the data from sessions in the database. How do you handle
the session data stored on the server and cookie on the users computer.
What excactly is it that you try to do?
Do you want to store the content of the cookie in the database?
Do you want to store the data in the session in the database?
Are you using a database to store the sessiondata in? (In contrast to using
flatfiles identified by the PHPSESSID?)
You can check this in your php.ini under:
session.save_handler = files

and where:
session.save_path = /tmp

and the name of the cookie:
session.name = PHPSESSID

I know how to destroy the session data and remove the cookie, but how do
you handle this problem.

I see three possibilities:

1. Do not remove the session data and cookie Security concerns?
If you are worried about sensitive data stored in the session, just destroy
it by hand when the user logs out or whenever you think is suitable:
// assign an empty array to session:
$_SESSION = array();
2. Remove the cookie, but not the session data Endless storage of useless
data on the server
No, PHP will destroy sessionfiles every X times somebody access a session.
So it periodically checks for old unused sessionfiles.
check you php.ini under

; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_probability = 1

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
3. Remove the session data and cookie
The problem with item #3, if you destroy the session data after
displaying the data on the users screen, and then the user refreshes the
page, he sees a blank page.


Whether the user sees a blank page when the session is lost, is up to you,
the programmer.

Regards,
Erwin Moller

Jul 17 '05 #2
Ken
Hi Erwin,

I do not have a problem but am interested in how others handle this.

"Should I destroy all session variables and the session cookie after I am
finished with them?"

If I destroy all session variables after the data is transferred to the
database by adding the destroy command to the final page;
if the user hits refresh F5 on the page, it goes blank.

The question I have how do others handle the not needed session variables
and session cookie?
1. Leave the session variables on the server and the session cookie on the
users computer?
2. Delete just the cookie on the users computer and leave the session data
on the server, even though it is not needed anymore?
3. Delete the session variables and session cookie?

Hope that helps.

Thanks for the response.

Ken

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:40*********************@news.xs4all.nl...
Ken wrote:

Hi Ken,

Can you clarify your problem a bit more?
I am confused. :-)
I am curious how others solve this problem.

After storing the data from sessions in the database. How do you handle
the session data stored on the server and cookie on the users computer.
What excactly is it that you try to do?
Do you want to store the content of the cookie in the database?
Do you want to store the data in the session in the database?
Are you using a database to store the sessiondata in? (In contrast to

using flatfiles identified by the PHPSESSID?)
You can check this in your php.ini under:
session.save_handler = files

and where:
session.save_path = /tmp

and the name of the cookie:
session.name = PHPSESSID

I know how to destroy the session data and remove the cookie, but how do
you handle this problem.

I see three possibilities:

1. Do not remove the session data and cookie Security concerns?
If you are worried about sensitive data stored in the session, just

destroy it by hand when the user logs out or whenever you think is suitable:
// assign an empty array to session:
$_SESSION = array();
2. Remove the cookie, but not the session data Endless storage of useless data on the server


No, PHP will destroy sessionfiles every X times somebody access a session.
So it periodically checks for old unused sessionfiles.
check you php.ini under

; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_probability = 1

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
3. Remove the session data and cookie
The problem with item #3, if you destroy the session data after
displaying the data on the users screen, and then the user refreshes the
page, he sees a blank page.


Whether the user sees a blank page when the session is lost, is up to you,
the programmer.

Regards,
Erwin Moller

Jul 17 '05 #3
"Ken" <kk******@wi.rr.com> wrote in message
news:4A*******************@twister.rdc-kc.rr.com...

I do not have a problem but am interested in how others handle this.


After setting session.auto_start set to 1 in php.ini, I don't have to mess
with non of them session_* functions no more.
Jul 17 '05 #4
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<zd********************@comcast.com>...
"Ken" <kk******@wi.rr.com> wrote in message
news:4A*******************@twister.rdc-kc.rr.com...

I do not have a problem but am interested in how others handle this.


After setting session.auto_start set to 1 in php.ini, I don't have to mess
with non of them session_* functions no more.


I'm curious to know the reason. (Chung's ideas are sometimes hard to follow;-) )

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
Ken wrote:

Hi Ken
Hi Erwin,

I do not have a problem but am interested in how others handle this.

"Should I destroy all session variables and the session cookie after I am
finished with them?"


No.
But I don't understand why you worry about the user that reloads the page.

Here is how I approach it, and I don't run into your question.
Hope this helps to clarify the issue. :-)

If you decide 'you are finished with the session', that is probably because
your visitor decides to log out or something like that.
If your visitor log out, you send him to a page (logout.php or something)
which contains some code that clearly ends the session.
If you are polite you also say to your visitor: "Your session ended, hope to
see you again soon!" or something like that.
If he reloads that page, he'll just get the same message.

suppose you stored in the session if somebody logged in correctly using some
username/password:

$_SESSION["authenticated"] = "Y";

and you check on all php-pages where authentication is needed for the
existence and correct value of $_SESSION["authenticated"].

if ($_SESSION["authenticated"] != "Y") {
// go away!
header("Location: loginhere.php");
exit;
}

OK?

Then in logout.php you only have to delete all sessionvariables by the
simple command:
$_SESSION = array();
which sets the session to an empty array, so no $_SESSION["authenticated"]
will exist.

This will not destroy the session, but will empty it, making it useless to
come back to pages that require $_SESSION["authenticated"] == "Y"

If you wonder what happens to the file after the session ends, that is
decribed in php.ini. I gave you the relavant entries in my last posting.
(session.gc_probability = 1 and the like, that detirmine when PHP decides
to do a session-garbage-collection round by checking all the sessionfiles)

But you don't have to worry about that, because the php executable will take
care of that. You can however use it to finetune the behaviour of heavily
visited sites.

To summarize:
1) Make sure you start a session with your visitor. (by cookie or
URL-rewriting)
2) store in the session all relevant data. (like if the visitor has rights
for this or that page)
3) When the user logs out: empty the session.
4) Make sure you check the session for the correct values of the visitor on
all pages where extra rights are needed.

Hope that helps!

Regards,
Erwin Moller
Jul 17 '05 #6
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
After setting session.auto_start set to 1 in php.ini, I don't have to mess with non of them session_* functions no more.
I'm curious to know the reason. (Chung's ideas are sometimes hard to

follow;-) )


Why not? I've yet heard an argument against using session autostart. When
it's on, $_SESSION is useable at all time. You don't need to worry about
calling session_start() and session_destroy(). The $_SESSION array
essentially becomes a place to put persistent variables. Too often people
try to implement user login session as a PHP session and end up getting
totally confused ("if session_start() is used to start a new session, why do
I have to keep calling it??!!!"). It is far easier to have a session at all
time--whether the user is logged in or not--and then use a session variable
to indicate the login state.
Jul 17 '05 #7
Chung Leong wrote:
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
> After setting session.auto_start set to 1 in php.ini, I don't have to mess > with non of them session_* functions no more.


I'm curious to know the reason. (Chung's ideas are sometimes hard to

follow;-) )


Why not? I've yet heard an argument against using session autostart. When
it's on, $_SESSION is useable at all time. You don't need to worry about
calling session_start() and session_destroy(). The $_SESSION array
essentially becomes a place to put persistent variables. Too often people
try to implement user login session as a PHP session and end up getting
totally confused ("if session_start() is used to start a new session, why
do I have to keep calling it??!!!"). It is far easier to have a session at
all time--whether the user is logged in or not--and then use a session
variable to indicate the login state.


Agree 100%.
That's how I approach it after getting frustrated trying it the other way
(like you described).
Just always create a session, and store the the userid, authentication,
whatever in the session.
Works like a charm. :-)

Regards,
Erwin Moller

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2023
by: José Landoni | last post by:
Hi, I got a problem with session_destroy function I created a script but it wont work, it goes like this: <?php session_start(); session_unset(); session_destroy();...
2
3289
by: Mat | last post by:
Hi, I'm trying to renew a session by using session_destroy() before starting a new session on the next page. Unfortunately, it seems that I keep getting the same SESSID (using $_REQUEST) when the...
2
2462
by: Per Johansson | last post by:
I have two files login.php and loggedin.php. If I understand $_SESSION correctly, its values should stay in place when I go from login.php to loggedin.php, right? They won't, $_SESSION gets cleared...
3
6490
by: Derek Fountain | last post by:
The documentation says session_destroy() "destroys all of the data associated with the current session". Um, like what? The docs further say that you should remove all information in the _SESSION...
9
2620
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
2
1145
tolkienarda
by: tolkienarda | last post by:
hi all i am having a problem with destroying my session variables, is session_destroy() the correct way to destroy all session variables. thanks eric
2
1311
by: mercedes1954 | last post by:
Hi, I am using header("Location: in two places in my script, but they are in mutually exclusive blocks i.e if one runs, the other can't. However, an error is thrown pointing to the...
7
1804
by: Jivanmukta | last post by:
Hello, I am learning PHP5. I have a website that consists of two pages: index.php and summary.php. In index.php the user is automatically moved to summary.php with some $_SESSION data so I use...
1
23058
by: phpuser123 | last post by:
Hi,I have created a script where I want to use onclick event and javascript to log out.Here r my coodes .. <script type="text/javascript"> function logout(){ <?php...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.