Hello,
I have created my own script to store session information and session data in a database. My script uses MySQL 5.1, PDO and prepared statements for database interactions. My PHP version is 5.2.14.
The prototype works great.
I’ve started adding the proper escaping of data. The problem starts when I use htmlentities to wrap the session data during the write function. Some how htmlentities is breaking the serialization of the session data. When it writes data that has been htmlentitied, the data gets nulled.
On my index page I start a session and set a session variable to ‘Hello World’:
Here’s the results from the write function on the index page:
ID: 3mcib19jgg43l9rmov2esskrv5
DATA: test|s:11:"Hello World";
USERAGENT: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
I click a link to the next page which starts a session but does not set a session variable. The results from the read function on the second page:
ID: 3mcib19jgg43l9rmov2esskrv5
DATA: test|s:11:"Hello World";
USERAGENT: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
The results from the write function on the second page:
ID: 3mcib19jgg43l9rmov2esskrv5
DATA: test|N;
USERAGENT: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
If I remove the htmlentities, it works like charm. Anyone else had this problem? Anyone got a suggestion for a fix?
Here’s part of the write function:
$session_data = htmlentities($session_data, ENT_QUOTES, 'UTF-8');
$sql = 'REPLACE INTO table (sessionion_id, sessionion_data, session_expires, httpUserAgent) VALUES (:sessionid, :sessiondata, :sessionexpires, :httpUserAgent)';
TIA,
Noob