[Solved] php include function leaves my page blank [closed]


Here:

First file: (index.php I presume?)

<div id="navigation">
<?php include 'menu.php'; ?>
        </div>
    <div id="content">
<?php
    echo "Hello World!";
?>
</div>
    <div id="footer">
    <?php include 'footer.php'; ?>
    </div>

Menu:

<?php
echo '<ul>
    <li><a href="https://stackoverflow.com/questions/23702104/index.php">main</a></li>
    <li><a href="info.php">php info</a></li>
    <li><a href="wda1.php">Assignment 1</a></li>
    </ul>';
    ?>

Footer:

<?php

echo $filename="https://stackoverflow.com/questions/23702104/index.php";

  if (file_exists($filename)) {
    echo "This page was last modified: " . date ("F d, Y H:i:s.", filemtime($filename));
}

// else not required but will show nothing if file doesn't exit
// you can remove it, it's optional
else{
echo "<br>This is not index.php. But will still show the filename above this.";
}

?>

Here is a summary of the mistakes made:

1) echo "<ul><li><a href="https://stackoverflow.com/questions/23702104/index.php">main</a></li>

  • You either escape the double quotes \" for your hyperlinks, or just wrap your echo using single quotes as shown in my answer above; it’s a lot less work.

then:

2) echo "$filename="https://stackoverflow.com/questions/23702104/index.php"; ... }";

  • You’re wrapping that entire code in double quotes, hoping it will do just that; echo. This will generate a parse error, which is almost a carbon copy of what you did in point #1.
  • Removing the first double quote before $filename then getting rid of the last one }";

Troubleshooting tip(s)

Add error reporting to the top of your file(s)
error_reporting(E_ALL); ini_set('display_errors', 1); this will signal any errors found in your code and guide you along.

For more information on error reporting, visit PHP.net:

solved php include function leaves my page blank [closed]