Current location: Hot Scripts Forums » Programming Languages » PHP » session question


session question

Reply
  #1 (permalink)  
Old 11-06-09, 04:28 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
session question

Hi there..

We run a Magento Webshop at the moment. This shop creates 8 sessions by itself.
For a affiliate program I want to add "my own" session (named: affiliate).

I create this with:
PHP Code:

$_SESSION['affiliate']  = 'yes'
When I echo my sessions this is in the list as it should be.. so far no problems.
Now I'm wondering how long the session lasts and can I set the lifetime for this
session only? So I don't mess up the other sessions that are created by Magento.

And is a session destroyed when the browser is closed, right? Or only after session_destroy
and after the lifetime expires?..

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-06-09, 07:07 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Session data persists according to the php.ini settings - including the garbarge collection and cookie lifetime on the browser. Different approaches may be used to clean up session data. I use a cron job to clear unused sessions after 24 minutes.

Firefox (2 and 3) let me return to a session if I reopen the browser within a short time, IE doesn't. The session data lasts as long as the person is logged in, if they log out, the data may still be there, but it might not be accessible, or the data may be gone.

It's good to test for session variables with isset, although you can probably assume if it reached your code, a session is in progress.

If I were you, I'd just use the session variables as above and not worry about it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-06-09, 10:14 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
is it also possible to get the remaining lifetime of a session?

I set it to:
PHP Code:


session_cache_expire
(15);
session_start();

if(!isset(
$_SESSION['user'])){
    
$uniek_sec date("U");
    
$uniek_ip $_SERVER['REMOTE_ADDR'];
    
    
$uniek md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);    
    
    
$_SESSION['user']  = $uniek;
    
} else {

echo
"session still running";



This should create a session with the name "user" that lasts for 15 min.
And then if the session exists it should echo the "session still running"
message.

If not it should create the user session as written above..

This is the way to do this?.

I noticed also that a session is not expired after 15 min.

_j

Last edited by jonnekke; 11-06-09 at 10:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-07-09, 01:48 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Sessions can be tricky, and the behavior varies by browser, server, and user actions.

I recommend trusting the cart's session management. As far as I know, there is only one session - although there may be many session variables.

What's really happening is that there is a file, usually stored in /tmp, with all the data for the session, which is read and updated as the user makes requests from and responds to the server. At the same time, there's a cookie on the client side, which stores the session id and perhaps some other data. The amount of time these files persist defines the length of the session.

When you work with open source software, the less you change, the better. Try to keep any modifications as simple as possible, and avoid modifying the original code - either fit into the architecture with modules, or use includes. It can be really difficult to avoid breaking the cart or adding security problems. If you feel like you need to make a lot of changes to use Magento, you might want to pick a different platform.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-09-09, 08:54 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Well said wirehopper. Upgrading becomes a nightmare when you have a slew of customizations.
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-09-09, 03:30 PM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
okey...thnx for that.

go one more session question.... hope you guys can also help me out here.... this has nothing to do with Magento or any other opensource application

I got a script that stores a product in a session as someone add a product to his basket (no login customer).
The product will be saved in the session for 15 min and the adding-time is set to determin this lifetime.

There is a problem if someone leaves the site by closing his browser. The product is still saved for 15 min.
Is there a way to fix this so the product will be "free" again if someone close the browser?...

I can't imagine but maybe there some kind of way..?

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-09-09, 04:54 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Unless the database is updated to indicate the product is in someone's cart, I'd just let the session time out and not worry about it.

The only other way would be to add a counter to indicate the number of each product in people's carts and update them as transactions completer or are abandoned.

Check out X-Cart. Shopping Cart Software & Ecommerce Solutions: X-Cart. Free shopping cart trial is available.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-09-09, 06:05 PM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
I'll think about how i'm gonna solve this.
Each product exists once.

I can't set the count back to 0 if someone
close his browser,so that wouldn't solve my
problem. I think i just let the product in
reservation for 15 min like it works right now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Security (Continued from post below) nova912 PHP 1 09-05-06 10:29 AM
Injecting a string into an If Statement ? nova912 PHP 4 07-21-06 03:04 PM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 04:54 PM
Simple Session ID Length Question? nova912 PHP 1 06-11-06 05:30 PM


All times are GMT -5. The time now is 11:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.