Jump to content

Undefined variables! when used on a different server!


Recommended Posts

Hello

I moved my site from an older host which was running PHP 4 to another one which had PHP4 and am getting error messages saying variables not defined.

 

Variables are filled through input boxes and send to the next page to be send to the next page for a calculation but they do not get recognized in this second page.  The host company's (Hostway, avoid them like hell) misrable support says it has to do with setting of flags on PHP and they want $150 to fix the problem!  How can I fix this myslef?

 

In case it help you to understand the problem better I post part of the code here:

 

<form method=POST action=calculate.php>

<input type=text name=NAME1>

<input type=text name=COURS1>

<input type=text name=FEE1>

<input type=submit>

</form>

 

 

In the next page (calculate.php) I have:

 

Hello <?php print $NAME1 ?>

 

 

but nothing is seen (error log shows says that variable NAME1 is not defined!)

 

 

Link to comment
Share on other sites

1) What's the difference between PHP4 and PHP 4?

 

2) Put this at the top of your code and tell me if there is a more specific error:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

3) Put quotes around your parameters

 

</pre>
<form method="POST" action="calculate.php">
<

 

etc...

 

4) On calculate.php it should be:

 

Hello <?php print $_POST['NAME1'] ?>

Link to comment
Share on other sites

2) Put this at the top of your code and tell me if there is a more specific error:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

 

That's exactly the reason for those messages[1]. E_ALL includes E_NOTICE, which informs about undefined variables. Disable E_NOTICE to get rid of it.

 

error_reporting(E_ALL ^ E_NOTICE);

 

[1] Clarification: The real reason is of course because those variables are undefined. What I mean is: new host probably has E_ALL set as default error reporting level.

Link to comment
Share on other sites

Your code is dependent on register_globals and the undefined errors are telling you that the variables that would have been created by register_globals from the form's post variables are not. The way to eliminate the problem is to add code to set the variables from the corresponding $_POST variables.

Link to comment
Share on other sites

Thanks for the clarification Mchl!

 

Not at all... I didn't notice that register_globals was involved :(  So disabling E_NOTICE will stop messages from appearing, but the script will not work until either register_globals is enabled (seems to be worth 150$ in some places... man I got to change my job) or Logical1's script is fixed to use POST and/or GET global arrays.

Link to comment
Share on other sites

Thank you guys for so many replies. 

I made a typing mistake:  old host had PHP 4 and the new one has PHP 5.1.6 (I wrote 4 again).

i added that code you suggested on top of the page and am getting a lot of errors .  Here they are:

 

Notice: Undefined variable: C1_wanted in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 55

 

Notice: Undefined variable: C2_wanted in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 69

 

Notice: Undefined variable: C3_wanted in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 83

 

Notice: Undefined variable: C4_wanted in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 96

 

Notice: Undefined variable: CV2 in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 109

 

Notice: Undefined variable: CV1 in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 109

 

Notice: Undefined variable: CV3 in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 109

 

Notice: Undefined variable: CV4 in /var/www/vhosts/zingzing.com/httpdocs/F/2/calculate.php on line 109

 

This exact code was working on the old server why should it not be working on the new one?  Any idea as how to solve the problem?

 

Thanks in advance

 

 

 

 

Link to comment
Share on other sites

If all of those are referring to POST variables from your form, the answer has already been given -

 

4) On calculate.php it should be:

 

Hello <?php print $_POST['NAME1'] ?>

and

 

Your code is dependent on register_globals and the undefined errors are telling you that the variables that would have been created by register_globals from the form's post variables are not. The way to eliminate the problem is to add code to set the variables from the corresponding $_POST variables.

 

If those errors are not referring to POST variables from your form, then you would need to identify where they are originating from (post/get/cookie/session) and set them accordingly.

 

For anyone if a forum to help, you would need to post your code so that someone can see what the variables are and how they are being generated and used in the code.

 

 

Link to comment
Share on other sites

If the issue is that I have to change the code how come it was working before in the old server and not here anymore?  If I can avoid having to go through 1000s of lines of codes for different sections by changing the setting or flags I think I better do that?  what do you think?  What should be changed in the PHP setting?

Thanks in advance for the replies .

Link to comment
Share on other sites

You have already been told that the code relies on register_globals to "magically" set the program variables.

 

Register_globals were turned off in php4.2 in the year 2002 because of a huge security hole (session variables can be set by hackers by simply putting values on the end of the URL when your page is requested.) That was almost 7 full years ago. No code should still existing at this point in time in 2009 that still relies on register_globals. Your code should have been corrected at least 5 years ago. Register_globals have been completely removed in php6, so, now is the time to fix it.

 

The above information is not a secret. No one should be surprised in the year 2009 that code needs to be updated to fix a security hole that was discovered in 2002.

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.