469,352 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

how to end up session

exoskeleton
104 100+
hi there im about to code for a log-out and i try to code this session_destroy();
but it wont work...the value of the variable stl there.

please tell me sir expert on how to design a log out and how to design a no-cache to prevent the user to click back button of the IE going to log in page again after he log in..

thank you please help
Oct 4 '06 #1
5 11567
exoskeleton
104 100+
in addtion : i got this message if i write session_destroy

Warning: Trying to destroy uninitialized session

hi there im about to code for a log-out and i try to code this session_destroy();
but it wont work...the value of the variable stl there.

please tell me sir expert on how to design a log out and how to design a no-cache to prevent the user to click back button of the IE going to log in page again after he log in..

thank you please help
Oct 4 '06 #2
ronverdonk
4,258 Expert 4TB
If you want to destroy the variable in the $_SESSION use
Expand|Select|Wrap|Line Numbers
  1. unset($_SESSION['var_name']);
If you want to destroy the entire session, use this code snippet from the PHP documentation http://nl3.php.net/manual/nl/functio...on-destroy.php
[PHP]<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();
?> [/PHP]

Ronald :cool:
Oct 4 '06 #3
exoskeleton
104 100+
thank you sir...im very thankful for your brillian ideas...one more thing sir...ahmmm...if i declare the session is it automatic to create a cookie? coz in your sample given you also unset the cookie but i did not declare any cookie..

i know this is a newbie question ... hope you dont get ... you know.. im just a little confused little fellow coz i dont declare any cookie...

more power

If you want to destroy the variable in the $_SESSION use
Expand|Select|Wrap|Line Numbers
  1. unset($_SESSION['var_name']);
If you want to destroy the entire session, use this code snippet from the PHP documentation http://nl3.php.net/manual/nl/functio...on-destroy.php
[PHP]<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();
?> [/PHP]

Ronald :cool:
Oct 5 '06 #4
ronverdonk
4,258 Expert 4TB
The code I posted is copied from the PHP documentation and serves as a sample. As you can see the code line
[PHP]if (isset($_COOKIE[session_name()])) {[/PHP]
will only delete the cookie if it is set. You can take that code line out or leave it just in case you ever decide to set session cookies.

Ronald :cool:
Oct 5 '06 #5
exoskeleton
104 100+
Thank you very much sir

The code I posted is copied from the PHP documentation and serves as a sample. As you can see the code line
[PHP]if (isset($_COOKIE[session_name()])) {[/PHP]
will only delete the cookie if it is set. You can take that code line out or leave it just in case you ever decide to set session cookies.

Ronald :cool:
Oct 13 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Damien | last post: by
1 post views Thread by mudge | last post: by
5 posts views Thread by Abhilash.k.m | last post: by
reply views Thread by joseph conrad | last post: by
14 posts views Thread by aroraamit81 | last post: by
7 posts views Thread by aroraamit81 | last post: by
reply views Thread by TRB_NV | last post: by
1 post views Thread by Santosh | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.