Solved

modify php session time

Posted on 2009-04-01
3
420 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
[X]
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
  • 2
3 Comments
 
LVL 110

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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

739 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