SuperbHosting.net have generously
sponsored
dedicated servers to ensure
a reliable and scalable dedicated hosting
solution for BigResource.com.
|
|
Session_set_save_handler
I am using the session_set_save_handler to store session data in m database, but I am having some trouble with getting the session id back out of the database to check if there is a current id running.
The following the function I am using to _read the database
function _read($id)
{
global $_sess_db;
$id = mysql_real_escape_string($id);
$sql = "SELECT data
FROM sessions
WHERE id = '$id'";
if ($result = mysql_query($sql, $_sess_db)) {
if (mysql_num_rows($result)) {
$record = mysql_fetch_assoc($result);
return $record['data'];
}
}
return '';
}
In the code I call the session_set_save_handler from I am able to write to the database fine, but when I try to read from it to see if there is a session in progress I can't seem to get it show me the session id or anything...
include 'sessionhandler.inc';
session_start();
$_SESSION['name'] = "mysessionname";
echo "
the session data is: ".$record['data'];
[test to see if the session is there and that is equal to md5($_SERVER['HTTP_USER_AGENT')]
....
Perhaps someone can help. Hope it makes sense what I am trying to do. Thanks.
View Complete Forum Thread with Replies
Related Forum Messages:
Php, Mysql, And Session_set_save_handler
Due to the nature of the hosting environment I'm using, I am unable to use sessions the normal way (relying on session files on the host), as it is a load-balanced cluster of servers. As a result, I'm attempting to adapt my application to save session data in a database. I have a "session" class that has all the correct handlers (open, close, read, write, destroy, gc) and the class method have been registered properly. I have verified that session data can be written and read from the database. However, here is the issue I'm encountering. When I go to do something as simple as log in to my application, I can see that the session data is being written correctly (e.g., "username|s:6:ph2007;"), but in practically the same breath, the information is then written over with "username|N;". As a rule, I instruct the script to "reload" the page immediately after handling function input, to prevent actions being repeated detrimentally. I have verified that this causes the "overwrite" of my session data. When I turn off the reload functionality, I am shown the correct screen after logging in, but any other interaction with session data or even manually refreshing the page ends up clearing the session data. Code:
View Replies !
Session_set_save_handler And Error Handling
Let open, close, read, write, destroy and gc be PHP functions to save the superglobal array $_SESSION in a database. I would like to use the following code: [1] session_set_save_handler(open,close,read,write,gc) ; [2] session_start(); [3] if(!isset($_SESSION)) [4] { /* error handling */ exit; } /* session okay */ But what will happen, if (e.g.) the database is down? Means: What kind of error handling can or must be implemented within the functions open, close, read, write, destroy and gc to get a stable script? Of course, line [3] is not enough ...
View Replies !
Real Life Examples Of Mysql+session_set_save_handler
In my test setup using my own session handlers with session_set_save_handler and mysql, the session handler opens and close mysql connections. But what if my page also requires some mysql queries? Should I open a new connection or use the already opened one (opened by the session handler)? I have made it a good practice to close a connection after a query but if I do it with only connection open no session data will be written to my mysql table. I have seen some scripts using persistent connections but are not sure what would be the best for a real world environment.
View Replies !
|
|