Jump to content

Advanced Sessions Processing


OldManRiver

Recommended Posts

All,

 

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.

 

Thanks!

 

OMR

Link to comment
Share on other sites

All,

 

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

 

Q1:

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.

 

Q2:

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.

 

Q3:

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.

 

Q4:

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 = 30

so 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 above

I 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

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `whse`
--

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

--
-- Table structure for table `session_trap`
--

DROP TABLE IF EXISTS `session_trap`;
CREATE TABLE IF NOT 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.

 

Thanks!

 

OMR

 

[attachment deleted by admin]

Link to comment
Share on other sites

Q2:Quote

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.

 

This is normal behavour.

 

Q4:Quote

What are the settings for GC frequency in php.ini?

Changed order as follows to sync settings on Dev DT and Test box.Code: [select]; variables_order = "EGPCS"

variables_order = "GPCS"Found no frequency setting for these but foundCode: [select]max_execution_time = 30so assume sessions blow after 30 minutes, which is about when all is lost.

 

None of these setting are related in any way to sessions.

 

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.

 

If you really want to persist data over longer periods I would suggest using cookies.

Link to comment
Share on other sites

From thorpe:

Q4:

What are the settings for GC frequency in php.ini?

; variables_order = "EGPCS"

variables_order = "GPCS"

max_execution_time = 30

None of these setting are related in any way to sessions.

So what settings am I looking for?

 

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.

 

If you really want to persist data over longer periods I would suggest using cookies.

Never written a cookie, what is a good howto?  Thinking I need to do that anyway as I worked the DB side of things but the UID/PWD and some other session vars, just aren't passing from page to page right, especially into and out of the IFRAME I'm using, so they are also not getting into the DB right.

 

Thanks for help! Please respond again with more info!

 

Thanks again!

 

OMR

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.