0

I am moving a self made web app to newer computer. The old computer is running a 32 bit xampp in windows 7 32 bit (xampp-win32-1.8.3-5-VC11) and the new one is win 10 pro 64 bit. I organize all my web page on a folder that become a subfolder to the doc root. This folder have several subfolder for images, php codes, css styling. The problem is my web app broke and won't display some part of it like in the old server.

I have try different web server package (incl WAMP, and Turnkey) with the same result. I suspect there is problem in referencing the files in my html code but I try to change it a bit to no avail. What confuse me is why the same code work in the old server while not in the new server. I even try to install the same xampp 32 bit (same version as old server) on win 10 64 bit but it still broke the web app. As I suspect the problem in referencing files, also tried changing the -> img src="/images/header.png" with img src="../images/header.png" in header.php but it also does not work.

index.html part that will show header in browser:

<!-- BEGIN: Sticky Header -->
<div class="center-div">
<div id="header_container">
<div id="header" style="background-image: url(images/header_background.jpg); background-repeat: no-repeat;">
    <?php include('header/header.php'); ?>
    </div>
</div>
<!-- END: Sticky Header -->

header.php files

<a href="#"><img src="/images/header.png" alt="Insert Logo Here" width="1200" height="150" id="Insert_logo" style="display:block;" /></a>

Here is my directory structure:

mc
 |
 +-- index.html
 |    
 +-- header
 |  |  
 |  +-- header.php
 |    
 +-- images
 |  |  
 |  +-- header.png
 |  +-- header_background.jpg

I will access my web app my typing http://xxx.xxx.xxx.xxx/mc in the web browser. The old server will show the header part correctly with both the header_background.jpg and header.png shown on the web app. But the new server will just show blank. I am a relative newbie and I wrote this web app sometime ago. Any idea how to fix this? Many thanks in advance.

hanugro
  • 3
  • 2
  • 2
    do not put header.php inside subfolder. just use it in the same folder as index.html. and also try renaming index.html to index.php. then include header.php at the top of index.php – Vishwa Apr 30 '19 at 09:40
  • 1
    Have you checked [the Apache error log](https://unix.stackexchange.com/questions/38978/where-are-apache-file-access-logs-stored)? – KIKO Software Apr 30 '19 at 09:40
  • Have you checked the Reade and Write rights? Sometimes there can be an issue. After reading your last section, I would say the server is not executing your php Code. As Vishwa suggested rename the index.html to index.php – Kektuto Apr 30 '19 at 09:47
  • @Vishwa except for changing the file extension, I see no reason at all for the other advice you gave. – Federico klez Culloca Apr 30 '19 at 09:48
  • @FedericoklezCulloca less messy, easier to debug etc etc – Vishwa Apr 30 '19 at 09:50
  • @Vishwa I'd say it's more messy to have all your files lumped in a single directory. Maybe I wouldn't have a `header` directory, but a `fragments` one containing the various pieces can be helpful to know what files are without having to open them. – Federico klez Culloca Apr 30 '19 at 09:51
  • @FedericoklezCulloca it depends on the situation,right? OP's project being simple one, putting header(and/or footer) inside sub-folder make it unnecessarily messy. IMO, header,footer should be always accessible easily(at the root) – Vishwa Apr 30 '19 at 09:53
  • @Vishwa I think we'll agree to disagree on this one :) I suggest we stop here to keep the comments on topic. – Federico klez Culloca Apr 30 '19 at 09:54
  • @FedericoklezCulloca cheers mate! :) – Vishwa Apr 30 '19 at 09:55

2 Answers2

2

You have to rename index.html to index.php. Basically, you need to execute PHP code inside a PHP file. Right now, you are trying to execute some PHP scripts in HTML file.

miguelbemartin
  • 417
  • 3
  • 10
  • Good point, but this does not explain the blank page without the header_background.jpg. Oh, wait, it does! Since it is the background of the div that should hold the header image... it's size is zero when that image isn't there. Hanugro evidently didn't check the source code of the page. – KIKO Software Apr 30 '19 at 09:49
1

Because you are using php code (php tag) in html file. here you should change file name index.html to index.php

  • Ah, have just change the index.html to index.php and can immidiately see the header_background.jpg. I think the way I reference a file also wrong in the header.php as I must include ../images/header.png. BTW, is there a way to make the apache treat ".html" as ".php" so to save me from renaming and changing all files references in my web apps? Any idea why my old server works? – hanugro Apr 30 '19 at 09:56
  • @hanugro Yes, there's a way, but don't do that. It will just cause confusion again when you migrate back to a new server or someone else inherits your code. Conventions exist for a reason. – Federico klez Culloca Apr 30 '19 at 09:58
  • The header.png still won't show in my web browser reagrdless I use img src="/images/header.png" or img src="../images/header.png" – hanugro Apr 30 '19 at 10:03
  • yes you can.. try this https://stackoverflow.com/questions/6295141/server-not-parsing-html-as-php#6295204 – Learner_121 Apr 30 '19 at 10:12