Jump to content

session error??


chaiwei

Recommended Posts

Hi I got this with this.

 

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

 

Here is my script

<?php 
session_start(); 
$_SESSION['a'] = $_POST['lala'];
$a = 'abc';
?>

 

The $_POST['lala'] is not a defined variable;

It is same as NULL, (will cause the warning appear also)

 

How was it processing? Please advice?

 

Link to comment
https://forums.phpfreaks.com/topic/174296-session-error/
Share on other sites

Yes, the $_POST['lala'] is a variable not yet defined.

 

The warning will dissapear  if I defined $_POST['lala'] equals to empty string

$_POST['lala'] = '';

or anything else.

 

Another thing I discover was it will be register global issues.

My PHP version was 5.2.0 and register_global was turn off.

 

You try run this script:

1. first step

<?php 
session_start();  
$_SESSION = array();
$a = 'I will be in session for the second time';
print_r($_SESSION);
$_SESSION['a'] = $abc; 
?>

Array ( ) 
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

 

2. Remove the $_SESSION = array();

And refresh again.

Then you will see

Array (     [a] => I will be in session for the second time ) 
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

 

 

Link to comment
https://forums.phpfreaks.com/topic/174296-session-error/#findComment-918804
Share on other sites

you have to submit your post data no?

if your passing along a post to another page it will pick it up but for example on the same page it would be

if (isset($_POST['submit'])) 
{ // if form has been submitted 
switch ($_POST['submit'])
{
case 'Submit':
$_SESSION['lala']=$_POST['lala'];
// the you can pass it along to the session 

break;
case default:
break;

}
}

Link to comment
https://forums.phpfreaks.com/topic/174296-session-error/#findComment-918837
Share on other sites

Read the error message and do what it says -

You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off

Stop and start your web server to get any change made to the master php.ini to take effect and confirm that the settings were actually changed using a phpinof() statement in case the php.ini that you are changing is not the one that php is using.

 

And yes, you should always make sure that your form was submitted before you access any of the form data, otherwise your code will not operate as expected.

Link to comment
https://forums.phpfreaks.com/topic/174296-session-error/#findComment-918846
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.