Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

modify php session time

Posted on 2009-04-01
3
Medium Priority
?
425 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 1500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

618 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