Search code examples
phpini-set

Should I set ini_set() on every page of my websites or will it on the first page do?


I want to set two ini directives by ini_set():

ini_set("session.cookie_httponly","1");

and

if(/*cookies disabled*/){
    ini_set("session.use_only_cookies", "0");
    $url.=htmlspecialchars(SID);
}

Will it work to set it just on the first page (especially the first one) or should I provide it on every page of my project?

And if I should use it on every page: Is there any other option to change configuration settings if I haven't got the access to the php.ini and PHP configuration files on the server? Could I set it in other way? (e.g. by using another PHP function or .htaccess)


Solution

  • If you want those settings to apply to every page request you need that code to be present on every page. Placing it in one file and then using require() to include it would be the best way to handle it in your situation.

    You can try to set these values in your htaccess file but many web hosts disable this.