Unstoppable Domains

Include files

Spaceship Spaceship
Watch

j0n87

New Member
Impact
0
Hi

I have a website made in html.
I got like 20 different pages in the site, and i have just copied the index.html 20 times and changed the content in every page.
When i want to change something in the Menu, i have to edit all 20 files, and that take too much time.

Now i got a php host, and want to use the Include php thing.
I want like the Header and Menu as index.php, and use <?php include("index2.php") ?> in the content.

design7ez.jpg


I've searched around in google, but didnt find enough info about this,
so i hope you guys can help me.

Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
include("filename.php"); means just include the code from that file
include once("filename.php"); means include the code from that file but no more than once.
require("filename.php"); means include the code from that file but if there's an error, don't open the rest of the code.


Something like that anyway. Sorry, I'm half asleep


__________________________________________________

Further more...

I remember when I first started using includes and I didn't realize it included the code rather than the design in Dreamweaver (I was stupid :p ). But code the 'index.php' first of all, then take portions of it (the header and the menu will probably be a good idea if the menu is on the left) and save it as "head.php". Then in the index.php, use ..

PHP:
include ("head.php");

Repeat for the footer of the page.
 
Last edited:
0
•••
Also, you have mentioned that you have 20 pages, so you can use something like that:
Code:
<?

switch ($_GET["page"]) {
case 1:
   include("index1.html");
case 2:
   include("index2.html");
case 3:
   include("index3.html");
case 4:
   include("index4.html");
}

?>

so if you will go to yourwebsite.com/index.php?page=1 it will open index1.html, if you will go to yourwebsite.com/index.php?page=2 it will open index2.html, etc..

But first of all, make header and footer, as miseria mentioned.
 
0
•••
i got what u said miseria, but not what NuPagady said.
can you explain better, or someone else?
with the whole code?

this is what i tried, but didnt success:
PHP:
<?php include("head.php"); ?>

<?

include_once("content.php");

switch ($_GET["page"]) {
case 1:
   include("content.php");
case 2:
   include("downloads.php");
}

?>

<?php include("foot.php"); ?>
 
0
•••
add a break; after each include in the case
 
0
•••
Meh... :)

PHP:
/*You'll need links to the releveant pages. I.E. : 
<a href='index.php?page=2'>Downloads</a> Would include the downloads.php content, etc.*/

<?php 

include("head.php");
include_once("content.php"); 

switch ($_GET["page"]) 
{ 
case 1: 
   include("content.php");
   break; 
case 2: 
   include("downloads.php"); 
   break; 
} 

include("foot.php"); 

?>
 
Last edited:
0
•••
the break; thing didnt do anything difference.
when i change site, the last include file is still there.

is this how a index.php is builded?
 
0
•••
0
•••
j0n87 said:
i got what u said miseria, but not what NuPagady said.
can you explain better, or someone else?
with the whole code?

this is what i tried, but didnt success:
PHP:
<?php include("head.php"); ?>

<?

include_once("content.php");

switch ($_GET["page"]) {
case 1:
   include("content.php");
case 2:
   include("downloads.php");
}

?>

<?php include("foot.php"); ?>


Ok, I made an example for you. First of all, visit the link below to see how it works:
http://www.nupagady.info/j0n87/

There are 6 files in the folder: index.php, head.php, foot.php, content.php, downloads.php and empty.php

index.php:
Code:
<?

include("head.php"); [COLOR=red][i]// 1. script will include header[/i][/color]

switch ($_GET["page"]) { [COLOR=red][i]// script will check variable "page" from the link[/i][/color]
case 1: [COLOR=red][i]// If the link is index.php?page=[b]1[/b], it will include "content.php"[/i][/color]
   include("content.php");
   break;
case 2: [COLOR=red][i]// If the link is index.php?page=[b]2[/b], it will include "download.php"[/i][/color]
   include("downloads.php");
   break;
default: [COLOR=red][i]// If variable "page" is not specified, script will include "empty.php"[/i][/color]
   include ("empty.php");
}

include("foot.php"); [COLOR=red][i]// script will include footer[/i][/color]

?>

head.php:
Code:
This is header <br>
-------------------------------------------------
<br>
foot.php:
Code:
<br>
-------------------------------------------------
<br>
This is footer
content.php:
Code:
"content.php" file.<br>
If you'd like to include "downloads.php", <a href="index.php?page=2">click here</a>.
downloads.php:
Code:
"downloads.php" file.<br>
If you'd like to include "content.php", <a href="index.php?page=1">click here</a>.
empty.php:
Code:
If you'd like to include "content.php", <a href="index.php?page=1">click here</a>;<br>
If you'd like to include "downloads.php", <a href="index.php?page=2">click here</a>.

I have also attached the archive with all files. Download if you need it.


P.S. sorry for my broken english :]
 
0
•••
NuPagady, thank you very much for this.
Now it all works.
And there is nothing wrong with your english ;)

Edit**
Is it possible to change the numbers with words?
Like this: index.php?page=downloads
 
Last edited:
0
•••
j0n87 said:
NuPagady, thank you very much for this.
Now it all works.
And there is nothing wrong with your english ;)

Edit**
Is it possible to change the numbers with words?
Like this: index.php?page=downloads
Yes:

PHP:
<?

include("head.php"); // 1. script will include header

switch ($_GET["page"]) { // script will check variable "page" from the link
case content: // If the link is index.php?page=content, it will include "content.php"
   include("content.php");
   break;
case downloads: // If the link is index.php?page=downloads, it will include "download.php"
   include("downloads.php");
   break;
default: // If variable "page" is not specified, script will include "empty.php"
   include ("empty.php");
}

include("foot.php"); // script will include footer

?>
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back