Solved

modify php session time

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
phpmyadmin 3 33
echo time from sql to input type="time" 9 21
Checking if varaible is empty 6 32
php function to remove a file 29 18
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…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

863 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

18 Experts available now in Live!

Get 1:1 Help Now