Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

modify php session time

Posted on 2009-04-01
3
418 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 109

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 109

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
PHP not parsing ' character 12 46
Number of hours between date in DB and now 8 21
Wordpress Only run code if on a certain page 11 22
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 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