session problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

session problem

Post by pelegk2 »

iam working ith code that i didnt write
but the thing i wan to ask
i get thing like session values that are still in "memory"!
how can i delete them?
i do :
$sess = session_start();
isnt it enough to delete the old session?
thanks in advance
peleg
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Start a Session : session_start() (don't know why your attaching it to a variable though)

Delete all variables from a Session : session_unset()

Destroy a Session : session_destroy()
amarquis
Forum Newbie
Posts: 10
Joined: Fri Dec 19, 2003 3:53 pm
Location: Switzerland

Post by amarquis »

You could also use

Code: Select all

<?php
session_unregister('FIELD1'); 
session_unregister('FIELD2'); 
?>
if you don't want to delete all variables and remove them manually...
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thanks all of u
can u redirect me to a very good step by step session article
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

which version of php do you use? In case of doubt use the script at viewtopic.php?t=8815#65245
It might be that session_unregister() is not what you should use.
http://php.net/session#session.examples shows you how to use session data with php versions 4.1 or above
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

this are the values i got :

Post by pelegk2 »

PHP Version: 4.3.2
Display Errors: On
Error Level: E_ALL
Register Globals: On
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Turn register_globals OFF! If it's your server then you can drop a .htaccess file to change it. Else if you wanted to have it on......then...nevermind that =/....

Anyhow, you can follow volka's second link. It'll have a few examples of the usage of sessions. Anyway, here's one from good ol spoono:

http://www.spoono.com/php/tutorials/tutorial.php?id=36

another one off of the monkey:

http://hotwired.lycos.com/webmonkey/00/ ... rogramming

Good luck,

-Nay
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

why do i need to put the register_globals off?

Post by pelegk2 »

i tried to use the file .htaccess
but it isnt working for me:(
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

What did you put in the .htaccess?

I hope it's not a blank file =\

-Nay
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

very funny
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

To be honest you really shouldn't need to use .htaccess for this problem, and if you are not to sure about the .htaccess syntax then this will probably cause you more problems.

The best thing to do is to check out the PHP manual (try this... [php_man]session[/php_man]) because you can use sessions if you have register_globals on or off. The only difference is the way you read/write the session variables.

For example...
With register_globals turned on you can set a session variable simply using $_SESSION["name"] = "bob" but with register_globals turned off you do session_register("name"); $name = "bob"

Read the manual and all will be revealed :)
Post Reply