Category: "PHP"

PHP Sessions

I’m used to working on busy public servers. For my latest project, I have a server all to myself (what fun!). Could not understand why the sessions weren’t timing out.

The key php.ini settings that resolved the issue were the garbage collection numbers. After all, PHP doesn’t check the session files for timeouts on every request.

In addition, if you don’t assign a value to a session variable on every request, the timestamp on the file isn’t updated - so the session will timeout regardless of activity.

:oops:

PHP Sessions

http://us2.php.net/manual/en/ref.session.php

session.gc_probability
session.gc_divisor
session.gc_maxlifetime

Cookies

To use the cookie to limit the session length, regardless of activity, use session_set_cookie_params to set the lifetime of the cookie.

http://us2.php.net/manual/en/function.session-set-cookie-params.php

Developing PHP5 code on a PHP4 server, that also has PHP5

.htaccess to run PHP5 on a server that defaults .php to PHP4, when your ultimate target is a PHP5 server.

.htaccess file


RewriteEngine   On
RewriteRule   ^index.php5$      - [L]
RewriteRule   ^exec.php$        - [L]
RewriteRule   ^(.*)\.php5?$     index.php5?page=$1
DirectoryIndex  index.php5

The advantage of this architecture is that since all the pages are delivered through index.php5, they are processed as PHP5, although they are named as .php.

Also - if you have a PHP5 application, you MAY be able to use the same approach, if you put PHP5 and PHP4 on the same server.