View Full Version : Advanced Sessions Processing

12-09-2008, 02:34 PM

I have this site, that does not want to trap and keep session & class vars.

The back-end (SSH & FTP) are on a short time-out, so logging in is frequent, I wonder if the ISP also set the front-end the same, maybe explaining my problem, but not sure.

A friend suggested I use MySQL to trap the class and session vars. He uses that method due to load balancing. Not sure if this fixes it, if front-end logout is forced.

I have no experience doing such a thing, so am wondering where I can find good examples and HOWTOs. Did search, but didn't get much. Suppose I'm using the wrong key words.

A little help here would be appreciated.



12-10-2008, 04:38 PM

Working here and with IRC #php, so will try to answer all the Q's and add some more info I found:

Am I on a shared web server?No 1.) Dev box is SO (Stand-alone) WAMP DT box, 2.) Test box is SO Ubuntu Server 7.10, 3.) Prod box is RHE4. All dedicated boxes housed at site warehouse.

Do sessions work at all or do they work but are ending after a short time?Sessions work for about 15-30 minutes, but then go out.

What exactly are the symptoms?Even though sessions are working vars are not holding or passing from page to page. Doing "var_dump" on dev box show all vars and values including the basket, but not passing to the "basket.php" file. On Test box the "var_dump" shows only a minimal set of vars and all shopping cart basket vars are empty.

I've saved the screens, in both the states (toggling my checkbox) and from both the DT dev box and remote test box, to help you see my problem. First file has screens. Second file has the images.

What are the settings for GC frequency in php.ini?Changed order as follows to sync settings on Dev DT and Test box.
; variables_order = "EGPCS"
variables_order = "GPCS"Found no frequency setting for these but found
max_execution_time = 30so assume sessions blow after 30 minutes, which is about when all is lost.

Comments from LostBoy on Sessions Table:

Its pretty simple and it should handle the time outs. I would approach this by creating a session table

session table
record_id PK autonumber
user_hash user_id + current login timestamp to allow for multiple user records (unless you want to make a separate date field)
session_data (either 1 field packed separated by some delimiter or multiple fields, its up to you)

Then with each request, set the user_hash as a hidden field in the form or attached to the GET url in a link

When the data comes back, look up the user based on the hash value and pull the session data out for validation

Then generate the results adding the hash back into the page as aboveI generated the following SQL:
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
-- Host: localhost
-- Generation Time: Nov 18, 2008 at 01:36 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.6


/*!40101 SET NAMES utf8 */;

-- Database: `whse`

-- --------------------------------------------------------

-- Table structure for table `session_trap`

DROP TABLE IF EXISTS `session_trap`;
`s_id` int(11) NOT NULL auto_increment COMMENT 'Session Unique Record',
`s_sid` varchar(40) NOT NULL default '' COMMENT 'Session ID',
`s_name` varchar(40) NOT NULL default '' COMMENT 'Session Name',
`s_uid` varchar(40) NOT NULL default '' COMMENT 'Session UserID',
`s_uhs` varchar(40) NOT NULL default '' COMMENT 'Session UserID hash',
PRIMARY KEY (`s_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;I know it's not complete, but a start, so chime in on what else you think I need here. Also am thinking of creating a "basket" table so all the shopping cart info goes there, then this will hold the info, even if the customer logs out and then returns.

One of the scenarios I deal with, is the site has a printable order sheet, so customers come to the site, login, print the order sheet, go to their warehouse, hand write onto the printed order sheet, then come back to site to order. This process can span several hours, as most have large warehouses, with hundreds of the site products on their shelves.

Thinking about my code, I have some changes to make this morning, will see what those do and get back to you here.



12-20-2008, 06:46 AM

I went to the DB driven session, it works better, but still have areas in my pages where session vars still are not working right.

Mostly I have to add "if" statements to test which vars are not there and pull from DB, when not set. Still working through all this.