Jump to content

Sessions in PHP 5.2.3


Recommended Posts

I am having problem with sessions in PHP 5.2.3

 

I am getting:

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

 

How can I get sessions to work ?

 

Everything else is as expected.

Link to comment
Share on other sites

Even simple script like this gives me that error (it works on php 4.4.7)

 

<?php
session_start();
$counter++;
print ($counter);
session_register("counter");
?>

 

Here is some more info:

 

Session Support enabled

Registered save handlers files user sqlite 

Registered serializer handlers php php_binary 

[table]

[tr][td]Directive

Local Value Master Value

session.auto_startOffOff

session.bug_compat_42OnOn

session.bug_compat_warnOnOn

session.cache_expire180180

session.cache_limiternocachenocache

session.cookie_domainno valueno value

session.cookie_httponlyOffOff

session.cookie_lifetime00

session.cookie_path//

session.cookie_secureOffOff

session.entropy_fileno valueno value

session.entropy_length00

session.gc_divisor100100

session.gc_maxlifetime14401440

session.gc_probability11

session.hash_bits_per_character44

session.hash_function00

session.namePHPSESSIDPHPSESSID

session.referer_checkno valueno value

session.save_handlerfilesfiles

session.save_pathno valueno value

session.serialize_handlerphpphp

session.use_cookiesOnOn

session.use_only_cookiesOffOff

session.use_trans_sid00

Link to comment
Share on other sites

It all has to do with the PHP.ini configuration file.

From the PHP manual:

 

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

Note: register_globals: important noteAs of PHP 4.2.0, the default value for the PHP directive register_globals is off, and it was completely removed as of PHP 6.0.0. The PHP community discourages developers from relying on this directive, and encouragees the use of other means, such as the superglobals.

 

So your code should be written as follows:

<?php
session_start();
$counter++;
print ($counter);
$_SESSION['counter'] = $counter;
?>

Link to comment
Share on other sites

You have two problems, the code is dependent on register globals being on, but they are not (and you must rewrite your code to eliminate the use of the session_register() function) and for help with the specific error message, read my post in this link - http://www.phpfreaks.com/forums/index.php/topic,193575.msg870830.html#msg870830

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.