PHP as CGI - AddHandler

We are running PHP Version 5.2.10 as CGI.

I need to change the value of session.use_only_cookies to “On” , and as this is a shared server, I can’t modify the global php.ini

With php running as CGI, I can’t obviously use the php flags in .htaccess either.

If I grab a copy of the global php.ini , and modify it, of course the value for session.use_only_cookies can be changed, but it is only changed for that path. :frowning:

There are many, many paths, so replicating the modified php.ini is out of the question.

I came across this on one site

When php run as CGI

Place your php.ini file in the dir of your cgi’d php, in this case /cgi-bin/

htaccess might look something like this

AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php5.cgi

The site only basically runs php files. There are a few html files, but they are blank ‘index.html’ , so I assume there is no need to worry about htm* files

Is the above example what I need to have the PHP setting “session.use_only_cookies” set to “On” globally.

Thanks,

Jehoshua


<?php

ini_set( 'session.use_only_cookies', true );
session_start();

Thanks. Will the ini_set() be propagated throughout all other php files ? There are many different includes, in different paths. I guess as long as it is put in a path/file that all the other php files include, or at least before the session_start().

It will be set for the duration of the script.

Thanks logic_earth and hash. If I have the php files like this:

a.php


<?php
//other php code
include 'b.php';
//other php code
?>

b.php


<?php
//other php code
ini_set('session.use_only_cookies', 1);
include "/include/c.php";
//other php code
?>

c.php


<?php
//other php code
session_start();
//other php code
?>

will the session.use_only_cookies be set to 1 (true) in c.php ?

Thanks. :slight_smile: