Re: [PHP] php 5 and register_globals=off gives lotsa errors



You did more than just turn register_globals off. You also changed your
error warning level. You have turned notices on. Set the same error
warning level in your PHP 4 setup and you will see exactly the same
messages.

To be notice-free, your code should look like this:

$action = isset($_GET['action']) ? $_GET['action'] : null;

replace null in the above with whatever you want your default action to
be there if it is not provided in the URL.

-Rasmus

Wikus Moller wrote:
Hi to all.

I am having huge problems running my script, which worked fine on a
server with php 4 and register_globals turned on, on a server with php
5 and register_globals turned off.

I get errors around the area in my script where I use $_GET (not the
only error). For example the following code on my index.php file which
like many other sites I know, handles quite a large amount
if(action=="main"); etc etc. :

<?
$action = $_GET["action"]; //line 55
$sid = $_GET["sid"]; //line 56
$page = $_GET["page"]; //line 57
$who = $_GET["who"]; //line 58
?>

When I go to http://chillinglounge.net (where the error is located) I
get the following error message(s):

Notice: Undefined index: action in
C:\websites\chillinglounge.net\public_html\index.php on line 55

Notice: Undefined index: sid in
C:\websites\chillinglounge.net\public_html\index.php on line 56

Notice: Undefined index: page in
C:\websites\chillinglounge.net\public_html\index.php on line 57

Notice: Undefined index: who in
C:\websites\chillinglounge.net\public_html\index.php on line 58

Now if you would look at exactly the same script at
http://ranterswap.net you'd see absolutely no errors.

That's where I need your help. I know what is causing this error. I
believe it's the fact that register_globals is turned off.

But what I really want to know is: How do I fix it without trying to
turn register_globals on via .htaccess (because it doesn't work)?

Is there a function or some magic script that would to the trick?
Or do I have to recode my entire script and how?

.



Relevant Pages

  • php 5 and register_globals=off gives lotsa errors
    ... server with php 4 and register_globals turned on, ... I get errors around the area in my script where I use $_GET (not the ... Notice: Undefined index: action in ...
    (php.general)
  • Re: [PHP] php 5 and register_globals=off gives lotsa errors
    ... Or you could fix the script: ... server with php 4 and register_globals turned on, ... Notice: Undefined index: action in ... But what I really want to know is: How do I fix it without trying to ...
    (php.general)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)
  • Re: How to Add a Feeback Form
    ... I saw nothing in that script that indicates where the form is e-mailed to so ... Greg Maxey/Word MVP ... PHP or not. ... have the support available yet. ...
    (microsoft.public.frontpage.programming)
  • How best to show PHP source? (was: One page, multiple submit buttons)
    ... script to add to the top of a PHP script to enable showing its ... Maybe anybody submitting their own PHP code for critique here ... Anything posted to a newsgroup is a "snapshot" of what the ... there ought to be a FAQ for this ...
    (comp.lang.php)