Peculiar HTML / PHP browser problem

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Peculiar HTML / PHP browser problem

Postby rickturner646 » 29. December 2012 22:21

Hello, friends...

I have just installed XAMPP (v1.8.1) on a new machine running 64 bit windows 8, and have found a peculiar problem.

I have a local web site on the machine that has a home page written in PHP (an 'index.php' file in other words). This file does not do anything complicated - it simply includes a couple of CSS files to format some text, and should display some gif/jpeg images on the page as well.

If the included CSS and image files are in the same directory as the index.php file, and I refer to them by local filenames (e.g. "logo.gif", "local.css") then they load ok and the page displays correctly. So, clearly PHP at least is working as expected since it parses the PHP in the file and spits out syntactically correct HTML that the browser can render.

However, if I change the source PHP file so that the included CSS and image files have 'absolute' filenames (e.g. "C:\xampp\htdocs\myproject\images\logo.gif") then they don't display (even when the images are there). So, there seems to be some problem with file loading, which may be a root cause, but.....

...... the really, really weird thing is this - if I use Ctrl-U to display the source of the page that will not load correctly, I can cut and paste this into a new file (let's save it as 'test.htm'). If I now load this test.htm file directly into the browser (IE), it displays correctly - images and all....

So. clearly the generated HTML is correct and the files exist in the directories referred to, etc. I don't understand why the (generated) html file is not rendering correctly when I load the PHP, but the (same) generated HTML source loads perfectly in a browser. Consequently, this would seem to be an issue of some kind with Apache.

Any suggestions, anybody???

Mit Freundlichen Grussen....

Rick Turner



The XAMPP package seems to be installed correctly - Apache, PHP, MySQL etc all run and I've got no unusual errors in any of the logs.
rickturner646
 
Posts: 1
Joined: 29. December 2012 21:56
Operating System: Windows 8 64 bit

Re: Peculiar HTML / PHP browser problem

Postby Altrea » 31. December 2012 18:30

Hi rickturner646,

Every image source fetched in http context by the browser expects a valid URI requestable with help of http protocol again.
Your image source is not a valid URI (file:///c:/xampp/htdocs/myproject/images/logo.gif would be a valid URI) and is not requestable by the http protocol (file:// != http://).
Second one is a security feature. It would be a really big issue if a remote server could be able to execute/request any file saved on the clients computer.
It works if you save the file as local html file because it is a different context for your browser.

Why don't you want to use correct absolute (http://localhost/myproject/images/logo.gif) or relative (images/logo.gif) image identifiers?

The other possibility would be to render the image with the help of php (this would surely just work on the server, not on remote clients). This is normaly a technique to just show images after valid authentification and as i think is very useless in your situation just to use local file paths.

It is not an Apache issue. Apache sends the html path of your file just to your browser.

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 56 guests