如何访问php会​​话文件

I have a Yii application with cookie based login enabled.

So , every time a user connects to the application a session file gets created on the server (/var/lib/php5) related to the PHPSESSID.

One of the Session variables is the timeout (timestamp).

I want to create a php script which access all of these Session files , opens them , checks for the timeout , and if it is timed-out ,make some changes to a specific table in the database.

First problem , from within my php script I'cant open session files in /var/lib/php5. Permission denied.(AFAIK from my php script I try to open those files as Apache User , though I need to be superuser , how could that be done...on the fly ? -without changing file permissions)

Second problem. Even if I try from my php script to open the superglobal $_SESSION for a specific session id I still get the permission denied message.

$sSessId='la05bdm63rdmjevg4hfrcf17u6';
session_id($sSessId);
session_start();
print_r($_SESSION);

Any suggestions on how a php script can access those session files ? Many thnx in advance.

First you do not need to invoke session_start() because by default its true, to disable in the config/main.php

'session' => array (
'autoStart' => false,// by default is true

),

The best way to read session in Yii is by using the build in functions Yii::app()->session which is similar to the super global array $_SESSION.

Yii::app()->session['var'] = 'value';
echo Yii::app()->session['var'];

To unset a session variable

unset(Yii::app()->session['var']);

To remove a session variable

Yii::app()->session->remove('var')

to change the path to your session variable

'session' => array (
'sessionName' => 'Site Access',
'cookieMode' => 'only',
'savePath' => '/path/to/new/directory',

),

Hope this will help