views:

144

answers:

2

I'm using session_cache_limiter() and session_cache_expire() at the top of my PHP 5.1.0 script, just before my session_start().

From PHP help:

[...] you need to call session_cache_limiter() for every request (and before session_start() is called).

But what if I don't call session_start()? Will session_cache_limiter() and session_cache_expire() work without a session_start() after them?

Thanks!

A: 

Example taken straight from "PHP: session_cache_limiter" off php.net

<?php
/* set the cache limiter to 'private' */
session_cache_limiter('private');
$cache_limiter = session_cache_limiter();
echo "The cache limiter is now set to $cache_limiter<br />";
?>

Also, it depends on your definition of work, the functions will be called and will not throw an error if session_start() is not called, but thats pointless. The purpose of those functions are for sessions and in order to use sessions you need session_start() to be called.

Anthony Forloney
Does session_cache_limiter() still send headers if session_start() isn't called?
Frank Farmer
In the given example above, its value `'private'` evaluates to a specific header that is sent, I would imagine so simply on the fact that the example is used to change the header sent without calling `session_start()`
Anthony Forloney
Anthony,the function merely modifies the value of session.cache_limiter (which starts as the default value specified in the INI file at each request) and is the same as calling ini_set('session.cache_limiter','private').The reason is has to be called before session_start() is because session_start() outputs all the headers required for the session page, INCLUDING the caching headers (which are determined by the session.cache_limiter value)
eCaroth
Thank you for providing some insight, that I did not know of.
Anthony Forloney
A: 

NO, ssession_cache_limiter and session_cache_expire merely modify the values php uses for session.cache_limiter and session.cache_expire (which are used when generating the session headers in session_start()) - the functions don't actually send out headers themselves, else you couldn't use them before session_start()

eCaroth