Forum Moderators: coopster

Message Too Old, No Replies

Modifying php values

sessions and cookies problem

         

jehoshua

1:04 pm on Feb 26, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



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 garb 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. :(

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

What do I exactly do, to bring this about please ?

J

jehoshua

12:33 am on Feb 27, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Does anyone know how I can do this, or what is required, please ?

rocknbil

6:45 pm on Feb 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to change the value of session.use_only_cookies to "On"


If you're limited by environment, maybe we can explore **why** you need to do this. Maybe you can code around it?

penders

10:40 am on Feb 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have a common include/config for every page? You should be able to set this with ini_set() at the top of your script?

Interesting to note that session.use_only_cookies defaults to "On" from PHP 5.3.0

jehoshua

10:03 am on Mar 1, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



If you're limited by environment, maybe we can explore **why** you need to do this. Maybe you can code around it?


After a server move, I cannot run the admin side of a site. I have checked all files, and they compare okay to a backup before the move. Have also compared a db backup to before the move, that's okay also. The php settings are the same on the new server, except for this one (session.use_only_cookies), it was 'On" on the old site, and is "off" now on the new site.

So, I had to assume that was what was causing the problem.

Do you have a common include/config for every page? You should be able to set this with ini_set() at the top of your script?


Yes, there is. I have tried that, both with 'ini_set()' and also with @ini_set(), but it didn't let me use the admin part still. I have checked the obvious, like there are no php errors.

Interesting to note that session.use_only_cookies defaults to "On" from PHP 5.3.0


That will be good. I think that 'return' of being able to use .htaccess (set php flags) where php is run as CGI, happens in 5.3.0 also; I may be mistaken though.

Thanks,

J

penders

11:30 am on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The php settings are the same on the new server, except for this one (session.use_only_cookies), it was 'On" on the old site, and is "off" now on the new site. ... So, I had to assume that was what was causing the problem.


I very much doubt that this is the cause of your problem. This directive will only affect users who have cookies disabled in their browser. In fact, with it in the 'Off' (less restrictive) state it should not have any affect at all!? Unless another part of your code specifically relies on the session cookie AND the user has cookies disabled?! But if you have cookies enabled anyway then I can't see it having any affect?

I have tried that, both with 'ini_set()' and also with @ini_set(), but it didn't let me use the admin part still. I have checked the obvious, like there are no php errors.


You can try calling ini_get() immediately after calling ini_set() to see if the value has stuck or not...
echo ini_get('session.use_only_cookies');


Just to note, the '@' sign in front of the function call simply suppresses any errors that would otherwise be output.

Do you not get any other errors/warnings/notices?
error_reporting(E_ALL | E_STRICT); 
ini_set('display_errors',1);

jehoshua

3:42 am on Mar 4, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



I very much doubt that this is the cause of your problem.


Okay, my assumptions were incorrect on that. Thanks for the explanation on how it works.

You can try calling ini_get() immediately after calling ini_set() to see if the value has stuck or not...
echo ini_get('session.use_only_cookies');



The ini_get() after the ini_set() , returned a '1'. I also ran phpinfo() in the same script, and the values were:

session.use_only_cookies - Local:On Master:Off

Do you not get any other errors/warnings/notices?
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);


I read up on the 'E_STRICT' as the error reporting was already E_ALL; seems it's ok for php version I'm using. But when I added the E_STRICT , it caused this message in the error logs

[Wed Mar 03 22:19:35 2010] [error] [client my.ip.add.res] PHP Strict Standards: Non-static method Logger::instance() should not be called statically in /class/logger.php on line 228


and it also caused a 500 on the website, so I removed the E_STRICT .

It seems that the php setting of 'session.use_only_cookies' is not the cause of the problem.

Thanks for your help everyone.

penders

8:48 am on Mar 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



session.use_only_cookies - Local:On Master:Off


That's telling you that in php.ini (which you can't change) the setting is 'Off', but in the current script (which is what matters) it is 'On'.

[Wed Mar 03 22:19:35 2010] [error] [client my.ip.add.res] PHP Strict Standards: Non-static method Logger::instance() should not be called statically in /class/logger.php on line 228


This indicates that your Logger class was written for (or at least to be compatible with) PHP4. You are now running PHP5. To fix this particular instance it is probably just be a case of adding the static keyword to the method prototype. eg. In /class/logger.php:

public static function instance()


(You can add the 'public' keyword as well if it's not there already - this is the assumed value if it is omitted)

jehoshua

10:16 am on Mar 4, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



This indicates that your Logger class was written for (or at least to be compatible with) PHP4. You are now running PHP5. To fix this particular instance it is probably just be a case of adding the static keyword to the method prototype. eg. In /class/logger.php:


Thanks. I see in the new version, it has the static keyword; this new version is written for PHP5. It means a complete install/upgrade, but I think it would be worth it, as this current version is all writtem with PHP4 in mind.