PHP blank page in Prod server but all OK in local

Asked

Viewed 390 times

1

I have this script: and when I move it to the remote server a blank page appears, this is the only page on the site that gives this and I don’t understand why. On site everything is ok, no error and if I see the source code of the pag tb appears nothing. All blank

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require_once('conn.php');

spl_autoload_register(function($class) {
    require_once ('Classes/'.$class.'.php');
});

$database = new DB($db);

?>
<!DOCTYPE html>
<html>
    <head>
        <title>Pics Upload</title>
        <style>
        * {
            box-sizing:border-box;
            margin: 0;
        }
        div {
            font-size: 0;
        }
        #errors {
            color: red;
            font-size: 16px;
        }
        p {
            font-size: 13px;
            text-align: center;
            background-color: yellow;
        }
        .image {
            width: 33%;
            font-size: 0;
            display: inline-block;
        }
        .image img {
            width: 100%;
            border: 2px solid yellow;
        }
        </style>
</head>

<body>
<div id ="wrapper">
<h1>Display all images from Database</h1>
<br>
<a href="index.php">Home</a>
<br>
<a href="displayAll.php">Display all images from database</a>
<br>
<a href="mostVoted.php">Display the 3 most voted images</a>
<br>
<a href="imagesFolder.php">Display images from folder</a>
<form action="" method="POST">
    <label><br><br>Insert how many random images you want to see<br><input type="text" name="numRandom"></label><br>
    <input type="submit">
</form>
<?php
    setlocale(LC_ALL, 'pt_BR.utf8', 'Portuguese_Brazil');
    date_default_timezone_set('Europe/Lisbon');

    echo '<br><br>Total Rows (images) in Database: ' .$database->fetchRowCount(). '<br><br>';

    if (isset($_POST['numRandom'])) {
        $numOfRandom = $_POST['numRandom'];
        if ($database->inputRandomCheck($numOfRandom)) {
            $results = $database->selectRandomImage($numOfRandom);

            echo 'Total random images to display: ' .$numOfRandom. '<br><br>';
            echo '<pre>', print_r($results), '</pre>';

            $uppercaseDay = ucfirst(gmstrftime('%A'));

            ?>
            <div id="imgWrapper">
            <?php
            for ($i=0; $i<count($results); $i++) {
                ?>
                <div class="image">
                    <p><?php echo $results[$i]->image_name;
                        echo '<br>' .strftime($uppercaseDay.', %d/%b/%Y - %H:%M:%S', $results[$i]->uploaded); ?>
                    </p>
                    <p>Total votes = <?php echo $results[$i]->vote; ?></p>
                    <a href="<?php echo $results[$i]->link; ?>" target="_blank">
                    <img src="<?php echo $results[$i]->image_path; ?>"></a>
                </div>
            </div>
            <?php }
        }

        else if (!empty($database->errors())){
            foreach ($database->errors() as $error) {
                echo '<div id="errors">' .$error. '</div>';
            }
        }
    }

    else {
        echo 'Total random images to display:<br><br><br>';
    }
?>
</div>
</body>
</html>
  • The php version of both servers is the same?

  • Yes, this is the only page on the website where this happens... http://iwanttobesanta.com/picsUpload/ happens on the website of Andom images

  • 2

    The production server is the same operating system and file structure?

  • 4

    Quite pertinent comment from @Marceloaymone. remember that in web PHP is almost always run in environment *Nix that is case-sensitive while the vast majority of PHP programmers, program on Windows that is not. Also, I have never seen pass -1 to error_reporting(). Use one of the described values in the manual

  • I think it’s a problem with the BD connection and the BD class has something like this: or die();

  • 1

    Do you have access to PHP error logs on the remote server? There they are always saved, if the PHP guidelines change at runtime (ini_set()) are not enabled.

  • 1

    Just to say that I was able to solve, without realizing why it seems that in the "Else if (!Empty($database->errors)) {..." part there was some kind of conflict, I only removed the "Else" and left the "if" and it worked

  • @Miguel Which version of php were you using? I think this one question explains the reason for the error. Could the test change the line else if (!empty($database->errors())){ by: $erros = $database->errors();&#xA; else if (!empty($erros)){.

Show 3 more comments

1 answer

1

The problem may be on this line:

require_once('conn.php');

Or in this:

require_once ('Classes/'.$class.'.php');

You are calling another(s) file(s). What he(s) does(in)?

Something that helps to know where the problem is is to put a echo with something to print before and after the line where you suspect there is an error. For example:

require_once('conn.php');
echo 'Teste';

If you print it, it’s because the error isn’t there.

Another problem may be related to file encoding. If it is encoded with UTF-8, check that the "Include Unicode Signature (GOOD)" option is not checked. If it is, it can cause problems when using commands like header, session_start(), etc... for which there can be no type of printing before them (and the BOM is a printed tag in the generated html).

If after these checks the error is not located, please post the full content (Conn.php file) to help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.