php include

Conmiro

New Member
Messages
140
Reaction score
0
Points
0
My friend did it once and it allowed you to use php include to create a webpage auto where it would automatically put the navigation to the left, and ur stats to the top and w/e everywhere else.

The navigation file included links u could add to left nav which would update every other page so you wouldn't have to add the links to every page manually. It also had like the layout all made.

The file would look like this as far as I recall:

<php? include ('header.php') ?>
Whatever text u put here would end up in a certain cell of the table.
<php? include ('footer.php') ?>

I don't know what the header.php and footer.php files need to have though.
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
header/footer.php either have more php code (<?php echo "This is a navbar!"?>), or standard html code.

If using HTML code, you do NOT need to put in something like <html><body><img src='images/header.png' /></body></html> - the original document that's doing the including should already have the <html> and <body> tags in there, so you can just put "<img src='images/header.png' />" in header.php, and it'll include it as-is (I made this mistake lotsa times before I realized it was just including the text as-entered - really made the w3c validator angry XD )


Side note: PHP tags open with <?php, not <php?. Just giving a heads up, it won't work if it's opened the wrong way :)
 
Last edited:

geirgrusom

New Member
Messages
9
Reaction score
0
Points
0
As Livewire says, php include is like the #include preprocessor directive in C/C++
It simply cuts and copies code into the new document with one exception:
Even though include is inside <?php ?> tags, you still need to put this inside the included file, because include kinda temporarily cancels this.

so
Code:
<?php include("header.php" ?>

// ... header.php

<a href="http://www.someurl.com">URL</a>
Is correct. You do must not start an included page with ?> in order to add normal HTML.
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
also for correct syntax you would need a semi-colon at the end of the include

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

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
also, anything included will be executed as well.

if your file is include_me.php is this
Code:
<?php echo 'Hello World!'; ?>

Where the file is included, it will echo 'Hello World!'

You can avoid this behavior by making a function
Code:
<?php function say_hello()
{
    echo 'Hello World!';
} ?>

then including the file and calling the function say_hello()
 
Top