Solved

modify php session time

Posted on 2009-04-01
3
414 Views
Last Modified: 2012-08-14
Basically I'm trying to modify the php session expiration time (default 1400 sec = 24 min). I don't have access to php.ini  or to any apache configuration file.
After reading tones of forums, I ended up with this script:

-----------------------------------------------------------------
$garbage_timeout = 3600; // in seconds
ini_set('session.gc_maxlifetime', $garbage_timeout);

strstr(strtoupper(substr($_SERVER["SERVER_SOFTWARE"], 0, 3)), "WIN") ?
      $sep = "\\" : $sep = "/";
$sessdir = ini_get('session.save_path').$sep."my_sessions";
if (!is_dir($sessdir)) { mkdir($sessdir, 0777); }
ini_set('session.save_path', $sessdir);

session_start();
....code...
----------------------------------------------------------------

The default path for session saves is /tmp      ( I found this with ini_get('session.save_path'); )

The problem is that I can't create a separate folder in /tmp. If I login with an FTP client, I can go to tmp folder, create whatever I want and give whatever permissions I want. NOT happening via php script.
By default garbage collector cleans /tmp folder (where there are saves from all users sessions) after server default time (1440 sec). I need to create a subfolder in /tmp, so that garbage collector won't destroy my session variables before a specified time (3600 seconds in my case).

Many thanks in advance!
0
Comment
Question by:itst
  • 2
3 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24044708
You might want to look into using a database to hold the session data.  Or if you are running on a hosted server, ask the server administrators to show you how to change this.  They would have access to the php.ini and similar files.

HTH, ~Ray
0
 

Author Comment

by:itst
ID: 24059843
I am running on a hosted server ... I only have CPanel for administrative purposes. I don't know how to use "database to hold the session data". Could you pls be more specific? i asked them (hosting company) to increase the value for session.gc_maxlifetime only for my domain... they said NO. They will probably say NO for saving session data into a database.
The script from my first post should work if I could create folders via php...
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24062234
See the man page here for information on using sessions in a data base.
http://us3.php.net/manual/en/function.session-set-save-handler.php

This will require a lot of app=development work to implement, and you will need to have a good understanding of databases in general and probably MySQL in particular. I think your choices are either (1) do the research and the work to change the session handler or (2) find another hosting company.  If it were my situation, I would find another hosting company.  Ask their tech support about this question before you sign up for their contract.  

Wish it were easy, but I do not know of a better way.  Best, ~Ray
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Importing and exporting data Magento 1.x ? 4 34
Wordpress type image upload 10 28
Not needed 13 53
PHP loop not working 4 30
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now