-2

In my index.php I have:

<?php

require_once('./headers/hed1.php');

require_once('./headers/hed2.php');

require_once('./headers/hed3.php');

echo 'TEXT';

?>

When I run this on my pc (using XAMPP) I get the result I want: the output of the three require_once, and then the TEXT.

I uploaded it to a server, and the same code has a different output. I see first the TEXT, and then the three require_once.

I saw another post of someone with the same problem, but there was no solution. Why the output id displayed in a different way if it's onlyne? Is there a way to "reorder" the three require_once?

Thanks in advanced!

MPMP
  • 133
  • 1
  • 1
  • 10
  • 1
    php does not re-order code, nor does it execute out-of-order. The includes will be performed in the order they're specified in the code. If the output comes out scrambled, then that's something wrong with YOUR html, not the way PHP is including/requiring the files. – Marc B Nov 19 '13 at 19:39
  • Check if you don't have any error in your php. You can use `ini_set('display_errors', 'On'); error_reporting(E_ALL);` at the beginning of your script to be sure to get all php errors/warnings etc. – OlivierH Nov 19 '13 at 19:40
  • That's what I thought, but the same files work different in my pc and in the web. – MPMP Nov 19 '13 at 19:41
  • I checked for errors. I found none. – MPMP Nov 19 '13 at 19:42
  • Is this the exact code you're trying to run? What's happening in it? – Lauri Elias Nov 19 '13 at 19:45
  • 1
    I expect it's an issue with tables - improperly formatted information in a table (fields between `` tags, but not in `
    `s, for example) will be rendered before the table itself.
    – andrewsi Nov 19 '13 at 19:46
  • Next time, please give your code as it is on your site, not a simplified version of it. – Marcel Korpel Nov 19 '13 at 19:52

2 Answers2

5

Everything is OK with your code and it is echoed by the PHP properly, this is the output:

<table border="0" width=100%><tr><td>Hi!</td><td align=right><a href="index.php?login">Log in!</a>, <a href="index.php?register">Register!</a></td>main

The problem is in your HTML. It's invalid. The table is not closed. The elements are messed up. The browser simply renders it in the wrong order.

Frantisek
  • 7,485
  • 15
  • 59
  • 102
1

You've not understood how your code works, how html works nor apparently made any effort to investigate why this is not producing unexpected results.

The files are being included in the correct order. The output is being generated in the correct order. Unfortunately the HTML is malformed so your browser doesn't know how to render it properly.

If you 'view source' in your rowser you'll something like the following (reformatted for readability)

<html>
  <body>
    <table border="0" width=100%>
       <tr>
         <td>Hi!</td>
         <td align=right><a href="index.php?login">Log in!</a>, 
                    <a href="index.php?register">Register!</a></td>
         main
      </body>
   </html>
symcbean
  • 47,736
  • 6
  • 59
  • 94