LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2010, 01:56 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Php + mysql + old sessions


Hello LQ,

I know this isn't a php forum, but what can I say, Linux nerds do it the best and you guys always seem to have the best insight.

I come to you with a fairly simple problem which I am hoping has a simple answer. I am currently recording some information in a mysql table (it's actually a shopping cart) and it stores items in the shopping cart via a session identifier (session_id).

Now I know PHP auto removes stale sessions on it's own, but that doesn't remove them from the MYSQL table. So I was gonna make a cron script that ran once every hour that removed any MYSQL shopping cart item from the table if the original session_id that created it does not exist anymore.

From my understanding a session_id is an "actual" file located somewhere on the harddisk (is it not? correct me if I'm wrong), so I was going to do a simple check for each item in the shopping cart to check for it's original session file, if it didn't exist on the harddisk, then simply remove it from the mysql table.

What does LQ think about this?
Thanks for your insight d00ds.
 
Old 08-26-2010, 12:47 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
First let me state that I've never done shopping carts. But it sounds to me that it will work. The session info is stored in /tmp on my Slackware server.

On the other hand, I wonder why you store the temporary shopping cart in a mysql database and not in the session itself? It would save you the hassle But you might have a very good reason (e.g. max filesize for session file).

Code:
$_SESSION['items'][$item_id]=$number_of_items;  /* item_id is a unique key from the db and the assigned value is the number of items that the visitor wants to purchase*/
$_SESSION['items'][33]=2;
$_SESSION['items'][345]=4;
If you want to keep track of the costs
Code:
$_SESSION['items'][33]['cost']=311.25;
$_SESSION['items'][33]['num']=2;
$_SESSION['items'][345]['cost']=12.50;
$_SESSION['items'][345]['num']=4;
Once the visitor submits, you store the items from the session in the database.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL FOSS for managing user sessions on the web? CoderMan Programming 1 04-25-2009 01:18 PM
apache php mysql and sessions helpme0904 Linux - Newbie 1 08-08-2005 03:24 PM
sessions in PHP zowey Programming 2 12-26-2004 06:35 PM
SQL mySQL PHP and Sessions poeta_boy Programming 15 11-26-2003 06:36 PM
PHP Sessions RecoilUK Programming 1 04-21-2002 05:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration