-4

I have a small php script thats working fine on server but not locally, I tried a lot but can't seem to get rid of these errors and login:

Notice: Undefined index: page in /Users/myusername/Work/www/sabaqk/index.php on line 4

Notice: Undefined index: page in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 68

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 69

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 70

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 71

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 72

I'd really appreciate any help. Thanks!

animuson
  • 53,861
  • 28
  • 137
  • 147
eozzy
  • 66,048
  • 104
  • 272
  • 428
  • 1
    Your web server probably has notices and warnings disabled in error reporting and your local host does not. Anyways, this has been covered a million times on SO. – animuson Dec 10 '11 at 06:08
  • I'm not worried about the errors, but I can't login. On the server, I can. – eozzy Dec 10 '11 at 06:11
  • 1
    The first two errors are causing the others. Solve those by using array_key_exists() – 0x6A75616E Dec 10 '11 at 06:12
  • Not another header problem, can't you spent some efforts to **READ** and understand what are the error messages all about? – ajreal Dec 10 '11 at 06:16

3 Answers3

1

It is happening so because error_display must be off on your server, whereas it is "ON" on your local system.
if you really want to resolve these issue programmatically use isset condition to check all the variables that are coming up as undefined in your error log.

Jigar Tank
  • 1,654
  • 1
  • 14
  • 24
1

As I stated in comments, Your web server probably has notices and warnings disabled in error reporting and your local host does not. Since your local host has notices enabled, those notice errors are getting printed out near the beginning of your script, which is messing up the rest. When you attempt to set your sessions/cookies (whatever you're using), PHP is unable to do so because content (your errors) has already been sent and the headers along with it, so cookies can't be set anymore.

Do not just disable error reporting in your PHP script because 1) you won't fix the underlying issue and 2) those errors will still get sent to your Apache error log and the log will become a massive text file of worthless information.

This is a very simple issue to fix. Just check if your keys exist before attempting to use them, either using array_key_exists() if it's an array, or even simpler, just using isset(). This will get rid of your notice errors and ultimately eliminate your login problem.

animuson
  • 53,861
  • 28
  • 137
  • 147
-1

You can include the following two lines to turn off the warnings and notices:

error_reporting(0);
ini_set('display_errors', false);
Tim Withers
  • 12,072
  • 5
  • 43
  • 67