sessions question
Posted: Sun Oct 11, 2009 5:36 am
I am trying to grock sessions and have a question re multiple users / sessions:
I am building a multiplayer game and I would like to use php to do it using sessions (with session_start() at the top of the home page and the actual code in an include file). I want to use sessions so that during stage 1, stage 2 and stage 3 of the game, the players only have access to their session variables but then at stage 4, the session variables will be available to all the players. I have looked into it and most suggest the use of php and MySQL (which i do in fact plan to use in the end) ... but for now, I am just trying to understand the use of sessions and how they are stored / manipulated on the server.... they show up as arrays, so can I have an include file, with an array variable that pushes session information onto the array stack as new clients join the program?
My question is basically:
If clientA hits the page and a session_start() is initiated, and then clientB goes to the web site and their session_start() is initiated, is there a way for me to create an array that contains the session information for both (and subsequent) clients?
Basically the code I have to test this would be something like:
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<?php
include("players.inc");
?>
</body>
</html>
and players.inc file would be something like:
<?php
$sessarray = array();
array_push($sessarray, $_SESSION);
?>
(obviously, with a way to see if the session array already exists before its created, so it doesn't get reset every time)
When I try to echo out the $_SESSION after a session_start() has been initiated, i get > Array
But if I set an array variable, such as $sessarray = $_SESSION;
and then if I try to echo $sessarray[0], i get nothing.
Sorry for the longwindedness. Your patience and any help is greatly appreciated.
I am building a multiplayer game and I would like to use php to do it using sessions (with session_start() at the top of the home page and the actual code in an include file). I want to use sessions so that during stage 1, stage 2 and stage 3 of the game, the players only have access to their session variables but then at stage 4, the session variables will be available to all the players. I have looked into it and most suggest the use of php and MySQL (which i do in fact plan to use in the end) ... but for now, I am just trying to understand the use of sessions and how they are stored / manipulated on the server.... they show up as arrays, so can I have an include file, with an array variable that pushes session information onto the array stack as new clients join the program?
My question is basically:
If clientA hits the page and a session_start() is initiated, and then clientB goes to the web site and their session_start() is initiated, is there a way for me to create an array that contains the session information for both (and subsequent) clients?
Basically the code I have to test this would be something like:
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<?php
include("players.inc");
?>
</body>
</html>
and players.inc file would be something like:
<?php
$sessarray = array();
array_push($sessarray, $_SESSION);
?>
(obviously, with a way to see if the session array already exists before its created, so it doesn't get reset every time)
When I try to echo out the $_SESSION after a session_start() has been initiated, i get > Array
But if I set an array variable, such as $sessarray = $_SESSION;
and then if I try to echo $sessarray[0], i get nothing.
Sorry for the longwindedness. Your patience and any help is greatly appreciated.