Biz Connection FREE TRIAL + $75 GOOGLE ADWORD - FREE VOUCHER for YOU!

Session issue and php

We can manipulate sessions via .htaccess (or php.ini) There is another article about how to manage php.ini directives via .htaccess.

Anything is in php.ini can be c hanged via php.

Here it is a simple way you can change session life time and the place where session is stored (files on the server)

<?php

// set the initial  cookies path
$cookie_path = “/”;

// set the timeout value for the cookie
$cookie_timeout = 60 * 60; //1 h

// set the timeout value for the garbage collector   add a bit (10 min) on top to be sure  there is session data until the  cookie expires
$garbage_timeout = $cookie_timeout + 600; // 10 min

// set the PHP session id (PHPSESSID) cookie to our  custom value
session_set_cookie_params($cookie_timeout, $cookie_path);

// set the garbage collector – who will clean the session files  to our custom timeout
ini_set(‘session.gc_maxlifetime’, $garbage_timeout);

// get the OS we have on the server and set the separator
strstr(strtoupper(substr($_SERVER["OS"], 0, 3)), “WIN”) ?
$sep = “\\” : $sep = “/”;

//create and setup the “personal and custom” folder to store our session variables
$sessdir = ini_get(‘session.save_path’).$sep.”my_sessions”;
if (!is_dir($sessdir)) { mkdir($sessdir, 0777); }

//Init the sesion data
ini_set(‘session.save_path’, $sessdir);

?>

To check that oit works crate a new php file and run it twice. The fisrt time the variable will be storedand the second the stored carialble will be displayed.

If second time you do not get OLALA on your screen it means “bad luck – check and try again” or … we provide consultancy.

<?php

session_start();

session_register(‘olalaVAR’);
$_SESSION['olalaVAR'] = “OLALA”;

if (!is_set($_SESSION[olalaVAR']) echo “Reload the page” else echo $_SESSION[olalaVAR'];

?>

Random article

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Comment