开发者

My simple PHP includes aren't being parsed

I'm fairly decent with HTML and CSS, but I'm a total noob to PHP. I'm trying to set up a really basic PHP template on my website, which is currently at http://www.paulgrantdesign.com/test77/photography

If you use Inspect Element on the page, it looks commented out in Chrome, or isn't even visible in Firefox, so you might have to view source. But I added the line

<?php include('includes/header.php'); ?>

near the top. The php file exists, which conta开发者_StackOverflow社区ins a copied and pasted section of what was there before. When everything was in place just in the html file, it looked great. How come the PHP isn't including the file I'm asking it to?


Because your index.html page is not being parsed by the PHP processor. PHP is not, alas, magical. It's actually a program that's run by the server on files containing PHP code. When a client requests a PHP page, the source of the pages file is sent to the PHP program for pre-processing, and the output is streamed to the client. Hence the (recursive) name: PHP stands for PHP: Hypertext Preprocessor.

So, for <?php ?> blocks to be handled, the server must know which files that contains them, so it can be run them through PHP on the server side. Any file that's not will just send the code straight to the browser, uninterpreted. Depending on your server setup, you might be able to fix this by renaming index.html to index.php, adding a filetype handler for .html to be parsed by php, or several other solutions too numerous to go into. Check with your host!


The page where you have the <?php include('includes/header.php'); ?> code, needs to be a .php file as well :)


Your file is not treated as a PHP file, it is sent as-is by the server (this is a static page).

Try renaming your index.html to index.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜