Jump to content

[SOLVED] Regsiter Globals problem...


BigNaz

Recommended Posts

I apologise if this has been covered, but would appreciate if someone could forward me on to the correct topic if it has....

 

I have been developing a PHP5/MySQL based web application using an offline testing server. When I uploaded the first section (an administrator login area) to my fasthosts server I got all sorts of errors...

 

The first of which was a problem with using $SCRIPT_NAME, which appears to have been addressed by changing it to $_SERVER['PHP_SELF'].

 

The second problem is, on the live server the script looks for $_POST and $_GET variables which are causing error messages (something about 'missing index').

 

I have contacted Fasthosts support, and they are saying that the problem is caused by their servers having register_globals:off . As far as I am aware $_POST and $_GET should still work with globals off, am I wrong?? Or is there a method I should be using to avoid the errors???

 

Please help, this is the beginning of a rather large project and I need to get things started asap!

 

Regards,

 

BigNaz

Link to comment
https://forums.phpfreaks.com/topic/49628-solved-regsiter-globals-problem/
Share on other sites

post the lines of code that are causing errors.

 

It sounds like you need to do:

 

if( isset( $_POST['my_variable'] ) )
{
  $var = $_POST['my_variable'];
  // etc...
}

 

because they are displaying all errors and warnings. A default install of PHP does not display all warnings.

 

monk.e.boy

post the lines of code that are causing errors.

 

if($_POST['submit']) {
    // mysql query stuff goes here
}

 

and...

 

if($_GET['error'] == 1){
    echo "Incorrect Username/Password!";
}

 

I don't have the code in front of me right now, but from memory these are the lines causing the following errors...

 

Notice: Undefined index: submit in ***myserver***/user/htdocs/administration/login.php on line 16

 

Notice: Undefined index: error in ***myserver***/user/htdocs/administration/login.php on line 49

 

'submit' comes from a form on the same page, and 'error' is set to 1 and added to the URL if a num_rows query comes back as not being 1.

 

Any offers??

 

Regards,

 

BigNaz

If you are using the same script to display the form and receive input from the form, you need to test whether the index values are set before testing them:

<?php
if (isset($_POST['submit'])) {
//
}
?>

 

and

<?php
if (isset($_GET['error'])) && $_GET['error'] == 1)
      echo 'Incorrect Username/Password!';
?>

 

BTW, those are NOTICES not ERRORS. They are displayed because your host is displaying all messages generated by PHP.

 

Ken

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.