Link to home
Start Free TrialLog in
Avatar of breeze351
breeze351

asked on

PHP error message

I've been using $_SESSION var on this site.  But now I'm getting weird results.

My variable ($_SESSION['Last_Page']) is showing the wrong variable.   I have 2 pages Space_Display and Space_Edit.  They both call "Street_Print.php".  "Street_Print" executes a print inclusion.  I've got rid of the print logic, and the session variable still get;s set to "Space_Edit".  

I'm getting the following error if I select certain pages in a certain order.

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

The page is hosted on a remote server that I have no control of (HOSTING24.COM)

I've googled "register_global" and it tells me to change the servers php.ini

After more research, will this code work in my "index.php" and flow through all the pages?
php_register_globals=1

Thanks
Glenn
Avatar of Gary
Gary
Flag of Ireland image

The page is hosted on a remote server that I have no control of (HOSTING24.COM)
Confused - how can you change anything then?
php_register_globals was removed in PHP v5.4 so you shouldn't be even using that.
Danger!  Do not enable Register Globals!  For the background on Register Globals, you may want to read this article.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7317-Register-Globals-a-bad-idea-from-day-one.html

You can probably just add this to your php.ini file;
session.bug_compat_warn = Off
session.bug_compat_42 = Off

Open in new window

That said, if you visit the pages in a certain order and get a logic failure that is order-dependent, you may have a debugging cycle staring you in the face.  I expect that any such failure would not be related to the warning messages about bug_compat.
The classical problem with $_SESSION variables 'magically' changing values is that you are expecting two windows from the same browser to have different sessions.  They don't.  All windows of a particular browser share the same cookies including Session cookies.  To have two different sessions you need to use two completely different browsers or even machines.
Good point, Dave.  By "two completely different browsers" we mean one instance of Firefox and a different instance of Chrome.  If you have two instances of the same browser, they share the same "cookie jar" file, and this results in unwanted cross-pollination of the session data.  It's an issue that has been before the W3C and may be fixed some day.
Avatar of breeze351
breeze351

ASKER

This is not what is happening.
The session vars worked until several days ago.  I can't change the php.ini because it is hosted on "HOSTING24.com"  
This makes sense, because if I change the .ini it changes it to all users.

I'm only using Firefox as the browser.

The error is:

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

I was told to use "htaccess" to change the "register_global" by HOSTING24.

Where do I go from here?
And we're telling Not to turn register globals on.  You have some other error that is causing that message.  Possibly a variable name that is the same as a $_POST[] variable but is being used in a manner that triggers that message.
http://php.net/manual/en/session.configuration.php#ini.session.bug-compat-42
Wow, smh.  DO NOT turn on Register Globals.  Your scripts may start to fail as soon as you do that, or it may take a while, but register globals is dangerous, and Hosting24 is wrong about the cause of these messages.

I am 100% certain you can change this in php.ini without any collateral damage to any site -- yours or any others.  Almost all competently installed PHP servers have php.ini on a per-directory basis, with the WWW root providing the defaults for the site and the sub-directories overriding the root settings.

What level of PHP are you running?  You can use phpinfo() to find out.  Please let us know.

According to this page, these configuration settings can be set according to PHP_INI_ALL.
http://php.net/manual/en/session.configuration.php

According to this page, PHP_INI_ALL settings can be made in the PHP script itself.
http://php.net/manual/en/configuration.changes.modes.php

So please try adding these statements to the top of the errant script and let us know what happens.
ini_set('session.bug_compat_warn', FALSE);
ini_set('session.bug_compat_42', FALSE);

Open in new window

If I understand your answer:
Layoff the register_global.

When you say that there could be a var name with the same name as a $_POST[] name, I'm not sure what you mean. What would trigger the message?
Consider what these variables would mean if you had register_globals set on...  If you haven't read the article about register_globals, it's worth reading to understand the risks associated with something like this.
$id
$_SESSION['id']
$_GET['id']
$_POST['id']

Open in new window

What level of PHP are you running?
In Ray's example above, all four of those would be the SAME variable if register_globals is on.
... but subject to the request_order directive (an impossibly stupid idea).  Really, it's hard to program PHP around all of the overlapping configuration options!
Ray
I'm getting weird results.  Does the code have to be included in every page?
I'm now getting the same error in another page that previously worked!

When you say I need to added it to the script, do you mean on the page or in the inclusion.

I echoed the session variables after I added you code and they are some up as blanks.

I've attache two .php files
"Street_Print.php" get's called from several other pages.
"Setup_Picture_PDF_inc.php" is the PDF print inclusion.

When I delete all the code from "Setup_Picture" and echo the session variables, they all show up as blanks.
My bad.  I forgot to attach the files.
Street-Print.php
Setup-Picture-PDF-inc.php
Setup-Picture-PDF-inc.php can't work properly because it does not have session_start() at the top of the page.  ALL pages that are involved in a session and use $_SESSION variables MUST have session_start() at the top of the page.  ALL.
How to use PHP sessions:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11909-PHP-Sessions-Simpler-Than-You-May-Think.html

You want to create a simple test case -- the SSCCE -- that demonstrates the situation causing the unwanted messages.  And after you see the unwanted messages, add these lines to the top of the simple test case.  Then run it again and see if these settings cure the problem.
ini_set('session.bug_compat_warn', FALSE);
ini_set('session.bug_compat_42', FALSE);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial