Jump to content

how can you change session data after session_write_close ?


koolaid

Recommended Posts

Can i access and change session data after i commit the session? If so how. I want to keep the same session i dont want to destroy and write over it. i just want to add values. So for example i have:

 


session_start();
$_SESSION['blah1'] = "whatever";
$_SESSION['blah2'] = "i love my dog";

session_write_close();

 

a few pages later i want to change that data but i need to keep the same session id.  So for example

 

if (!session_id()) {
if (isset($_GET['session_id'])) {
	session_id($_GET['session_id']);
               $_SESSION['blah1'] = "new info";
               $_SESSION['blah2'] = "i love my dog";
               session_write_close();
}
session_start();
$_SESSION['blah1'] = "whatever";
$_SESSION['blah2'] = "i love my dog";
session_write_close();
}

 

well, if i remove all my session_write_close() it works in FF, but without session_write_close() the session does not function properly in IE. With the session_write_close() i cannot alter the session data in IE. Both methods work in FF. Any advise would be greatly appreciated. i am stuck here.

 

Thanks in advance,

Matt

Link to comment
Share on other sites

Page 1

session_start();
$_SESSION['blah1'] = "whatever";
$_SESSION['blah2'] = "i love my dog";

 

Page 2

session_start();
$_SESSION['blah1'] = "whenever";
$_SESSION['blah2'] = "i love my cat";

 

That is it. session_id() not needed. Why you are throwing the session Id through the url I dont know

Link to comment
Share on other sites

look at this page, it shows you how to do that mate.

 

http://uk.php.net/manual/en/function.session-write-close.php

 

read this one make sence.

 

The trouble was that SID was the same even after session_unlink() and session_write_close(). The session_start() function just restored the previous session data!!! So the script was not safe.

Then I added session_regenerate_id() call after each session_start().

<?php ....
session_start();
/*Getting user login and e-mail from database*/
$user_login = "....";
$user_id = "....."

/*CLOSE PREVIOUS SESSION*/
session_unlink();
session_destroy();

/*NOW GENERATING LINK FOR SESSION DATA */
session_start();
session_regenerate_id();//Regenerating SID for sending

$_SESSION = $user_login;
$_SESSION = $user_id;

/*here generating link:*/
$link = "http://host.com/restore=" . SID . "";
mail (....);

/*CLOSE THE SESSION WITH USER DATA*/
session_write_close();

/*AND STARTING ANOTHER NEW SESSION*/
session_start();
session_regenerate_id(); //Regenerating SID
/*THEN LOAD THE 'MESSAGE SENDED' PAGE*/
header("Location: /restore/message_sended/");

?>

Link to comment
Share on other sites

neil.johnson:

ignorance (answer to both questions). I am trying to get a hold on how sessions work. i have been reading on it, but it hasn't clicked yet. So i don not need to commit the session with session_write_close?

 

thanks redarrow!

Link to comment
Share on other sites

read on database session as well well good stuff mate even more powerful

http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/

 

you have a look at all the session function there grate fun.

there so powerful and so handy especially creating a e commence project.

 

in the future.

 

good luck best off luck.

 

 

ps. with database sessions you can have cross web site info now that amazing.

 

example let say your the admin off 5 web sites you created or got clients for, you can set the session in the database to have full admin access to all 5 web sites at once to administrate . love it.

 

if you think about it, and you was getting paid to administrate all them 5 web sites on call from each client to another what a grate function.

Link to comment
Share on other sites

No, not at all.

As my previous post. Once you call session_start() you have an active session. To add data to the session you simply use

$_SESSION['name'] = "neil";

 

easy. No need to commit anything.

 

If I want to overwrite that value:

$_SESSION['name'] = "koolaid";

 

Just make sure that session_start() is at the top of all pages where you are using a session. Sessions remain persistent through all your pages until you destroy it or it times out:

 

unset($_SESSION['name']);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.