Programming Forums
User Name Password Register

RSS Feed

Thread Tools Display Modes
Old Aug 28th, 2013, 3:41 PM   #1
Join Date: Nov 2011
Posts: 12
Rep Power: 0 Saruman_W is on a distinguished road
Issues with set_session_save_handler: read() called before write()

After reading some guides on the topic I decided I'd create a custom session handler class. But I've ran into an odd problem. The class was designed to store all Session information in a MySQL database. I know there are probably more efficient ways but right now I'm trying to figure out what I'm doing wrong.

Basically the problem I'm having is that the read() function of my Session wrapper class is being called BEFORE write(). Essentially it is trying to look for information that has yet to be written to the database. From reading the documentation of set_session_save_handler the only times write() is called is when PHP is closed or when session_write_close() is called. But that doesn't exactly help me here! I don't want to write() at the END of the session, that's useless! I'm trying to write() information then retrieve it (with read()) whenever I access $_SESSION data.

Am I thinking about this completely wrong? I appreciate any help! Here's the section of code where I'm using my custom session wrapper. If you need the actual wrapper code let me know:

public function login()
		$username = $_POST['txt_username'];
		$password = $_POST['pwd_username'];
		if($this->model->auth_user($username, $password));
			//TO-DO: Need to pass in the ID of the user being authenticated.
			//To do this though will need a new function in the DB class that
			//retrieves this
			$session = new SessionEngine($session_config);

					array($session, 'open'),
					array($session, 'close'),
					array($session, 'read'),
					array($session, 'write'),
					array($session, 'destroy'),
					array($session, 'gc'));
			$_SESSION['auth'] = true;
			$_SESSION['username'] = $username;
				error_log("******** Session data: ".var_export($_SESSION), 0);
			$this->Add('username', $username);			
			//header("Location: /");
Saruman_W is offline   Reply With Quote


php custom sessions mysql

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write and read a file with the same fopen laresistance2 PHP 2 Jul 17th, 2012 6:11 AM
how to read single letters of "awk element ? dut42 Bash / Shell Scripting 9 Apr 10th, 2011 9:49 AM
need some help on writing a code that display and write the result to a file rax_7 C++ 1 Oct 13th, 2010 7:48 PM
How do I read in web page with "frames" in them Striver Visual Basic 0 Feb 12th, 2009 10:19 AM

DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC