0

I have a simple web site with many PHP pages. Among them, some four pages use common variables, which I should store in the session object. But the thing is, these values should not be visible to other pages, so I decided to use session_name to create a new session. It will start a new session but these four pages are using the values from the old session, which is creating a problem when I try to print $_SESSION: it is an empty array after the start of my new session. I want this new session to retain the old values plus new values.

I'm not looking for this $_SESSION['page_group']['variable_name'] kind of solution as I cannot use arrays.

6
  • Welcome! I don't understand; why can't the other pages "see" the session variables? "Multiple initialized sessions per page" sounds like a bad idea. Commented Aug 18, 2012 at 18:18
  • @JaredFarrish Sounds like several web-apps on one server. Commented Aug 18, 2012 at 18:23
  • @JaredFarrish thanks,bcoz i need all these variables which i created in these four pages to be unset on particular check how many variables i created what variables i created i really dont have control over them using other session i can unset all the variables in that session by simply destroying the new session Commented Aug 18, 2012 at 18:25
  • I take it storing it in a table in a database by the session ID, checking the URL for the "right" page, and setting whatever variables from the table, isn't possible? (Which you should also purge of expired sessions.) Commented Aug 18, 2012 at 18:37
  • @JaredFarrish that's a possible solution, but is it not possible the way which i told what are possible difficulties if i try to do it that way? i.e., using two sessions sorry if i'm asking to basics i'm really new to multiple sessions concept. Commented Aug 18, 2012 at 18:46

1 Answer 1

1

How about using something like

session_start();
$temp=$_SESSION;
session_write_close();
session_name("newname");
session_start();

and then merge $temp into (the new) $_SESSION (where needed)?

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried the above mentioned code but there is a problem.If i'm trying to print $_SESSION after the new session_start before merging with $temp still i'm getting the values which are set for earlier sessions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.