2

I have a website built mainly with php. The problem i have is at the top i have a div with a background image. It has to be in a very specific place. Every time there is a PHP error the div gets moved down which then makes the page look bad.

I can think of two possible solutions but i dont know how to do them and searching the web has been a fruitless effort.

  • Make it so the php error doesnt push the div down (i tried float but the div has other things in it that need to be on the left side while the image is on the right)

  • Make the php errors appear elsewhere. (I have no clue how to do that and couldnt find anything)

Im using codeigniter. Thanks for the help.

Dylan Buth
  • 1,648
  • 5
  • 35
  • 57
  • Spend some time in your `php.ini` file - search the file for "error" and read through the comments. – Madbreaks May 10 '12 at 22:22
  • 5
    Also it's generally a good idea to actually fix the errors. – Mahn May 10 '12 at 22:35
  • I know its a good idea but some are unforeseen. If i see one i fix it. – Dylan Buth May 10 '12 at 22:37
  • 1
    Errors should be fixed. Unforseen errors should be handled gracefully. An end-user should never see raw error output. This is a big no-no. –  May 10 '12 at 22:45
  • 1
    why you not use the codeigniter environment futures? visit this link http://codeigniter.com/user_guide/general/environments.html – chhameed May 11 '12 at 07:00

5 Answers5

4

It doesn't matter what platform are you using, but errors from back end should always be written to log file and not to output in production. This is how you do it in PHP:

hakre
  • 193,403
  • 52
  • 435
  • 836
valentinas
  • 4,277
  • 1
  • 20
  • 27
2

The answer is that you never ever ever show PHP errors on a production server. You should only show them on your live server.

Therefore, while you are testing and building your application, it doesnt matter where the error shows up.

But on your live server, you need to hide the php error, whilst still logging. Codeignitier provides this ability.

Firstly, in your index.php change

define('ENVIRONMENT', 'development');

to

 if ($_SERVER['SERVER_NAME'] == 'localhost')
 {
define('ENVIRONMENT', 'development');
 }
 else
 {
define('ENVIRONMENT', 'production');
 }

this will automatically set Development mode for when you are on your localhost, and production mode when it is deployed (i.e. no code changes).

Now you configure a few things as needed:

inside Index.php also change the error reporting to:
if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(-1);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
 }


 Config.php
 // Set logs to show Debug + Error messages on your development
 // But only error messages on your production server
 $config['log_threshold'] = (ENVIRONMENT == 'development' ? '2' : '1');


 Database.php (config)
 $active_record = TRUE;
 $active_group = (ENVIRONMENT == 'development' ? 'localdev' : 'production');
 // Now define the two different groups here, making sure production has:
 $db['production']['db_debug'] = FALSE;
Laurence
  • 58,936
  • 21
  • 171
  • 212
2

All the above answers are the correct way to produce PHP CodeIgniter codes.

But to answer your question, if you have a personal preference, you may want to try using the z-index property when you define your image css.

It doesnt move your errors down, but your image will always be in the position you fix if the z-index of your image is higher than the z-index of the div that contains your errors.

https://developer.mozilla.org/en/CSS/Understanding_z-index

He Hui
  • 2,196
  • 4
  • 29
  • 46
1

The most obvious answer would be to make sure there are no errors. If this can't be done, add the following line to your PHP script:

error_reporting ('E_NONE');
Jeroen
  • 13,056
  • 4
  • 42
  • 63
0

A quick fix would be insert below code below <?php opening tag

<?php

error_reporting(0); // this will prevent the errors from showing

ini_set('log_errors', 1); // this will log the errors in the log file.

Hope this helps.

cherankrish
  • 2,004
  • 1
  • 16
  • 11