[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP error message

Posted on 2014-08-23
16
Medium Priority
?
226 Views
Last Modified: 2014-09-02
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
0
Comment
Question by:breeze351
  • 7
  • 4
  • 4
  • +1
16 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40280921
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.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40281005
Danger!  Do not enable Register Globals!  For the background on Register Globals, you may want to read this article.
http://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.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40281106
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40281123
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.
0
 

Author Comment

by:breeze351
ID: 40281806
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?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40281838
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
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40281884
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

0
 

Author Comment

by:breeze351
ID: 40281895
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?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40281979
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?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40282028
In Ray's example above, all four of those would be the SAME variable if register_globals is on.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40282061
... 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!
0
 

Author Comment

by:breeze351
ID: 40283913
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.
0
 

Author Comment

by:breeze351
ID: 40283925
My bad.  I forgot to attach the files.
Street-Print.php
Setup-Picture-PDF-inc.php
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40283944
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.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40283966
How to use PHP sessions:
http://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

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40283973
For Setup-Picture-PDF-inc.php, try this:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('session.bug_compat_warn', FALSE);
ini_set('session.bug_compat_42', FALSE);
session_start();
var_dump($_SESSION);

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question