lisovaccaro
lisovaccaro

Reputation: 34016

Include header, how to?

<html>
<head>
<!--#include virtual="header.php" -->
</head>

<body>
aa
</body>
</html>

I'm trying to put the header in a different file and call it with an include. But I can't make it work. Right now the only text in the header is the word header. The header is at: www.chusmix.com/game/header.php how can I call it? I don't care if I use include virtual, I just don't know how to do it.

Thanks

Upvotes: 0

Views: 213

Answers (3)

Erik
Erik

Reputation: 20722

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

Your include needs to be in PHP -- the way you attempted to include it is a very old method of SSI (sever side includes) and has nothing to do with PHP.

In order to include this way, the page doing the including must be parsed as PHP, and on most servers that means ending the filename with a .php extension. You can have plain HTML in a .php file so you can just rename the file (if its not already) to .php and then include the line I wrote above.

Upvotes: 3

usoban
usoban

Reputation: 5478

include('header.php')
include_once('header.php')
require('header.php')
require_once('header.php')

take your pick ;)

To clarify: include and require differ only as much, that if file does not exist, include will only display warning, while require will throw fatal error.

The *_once functions on the other hands make sure file is included only once. Try including the same file two times, you'll get an error. *_once makes sure the 'including' is done only once. On the other hand, *_once functions bring you a bit of overhead, but that should be taken in account when writing bigger applications.

Upvotes: 1

Femaref
Femaref

Reputation: 61497

You need to include it in the php code:

include (header.php);

Upvotes: 0

Related Questions