NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Include files

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-11-2005, 05:55 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Mar 2005
Posts: 9
j0n87 is an unknown quantity at this point
 



Include files


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.
????: NamePros.com http://www.namepros.com/programming/122733-include-files.html
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.



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

Thanks
j0n87 is offline  
Old 09-11-2005, 06:04 AM   #2 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




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 ). 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 Code:
include ("head.php"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=122733
Repeat for the footer of the page.
Last edited by Encenta.com; 09-11-2005 at 06:07 AM.
Encenta.com is offline  
Old 09-11-2005, 08:32 AM   #3 (permalink)
NamePros Regular
 
NuPagady's Avatar
Join Date: Jul 2005
Location: Lithuania
Posts: 482
NuPagady is on a distinguished road
 



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..
????: NamePros.com http://www.namepros.com/showthread.php?t=122733

But first of all, make header and footer, as miseria mentioned.
NuPagady is offline  
Old 09-27-2005, 03:03 PM THREAD STARTER               #4 (permalink)
New Member
Join Date: Mar 2005
Posts: 9
j0n87 is an unknown quantity at this point
 



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 Code:
<?php include("head.php"); ?>
????: NamePros.com http://www.namepros.com/showthread.php?t=122733

<?

include_once("content.php");

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

?>

<?php include("foot.php"); ?>
j0n87 is offline  
Old 09-27-2005, 03:48 PM   #5 (permalink)
Senior Member
 
legend2's Avatar
Join Date: Sep 2005
Posts: 1,112
legend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud of
 



add a break; after each include in the case
legend2 is offline  
Old 09-27-2005, 03:53 PM   #6 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Meh...

PHP Code:

/*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");
????: NamePros.com http://www.namepros.com/showthread.php?t=122733
include_once(
"content.php"); 

switch (
$_GET["page"]) 

case 
1
   include(
"content.php");
   break; 
case 
2
   include(
"downloads.php"); 
   break; 


include(
"foot.php"); 

?>
Last edited by SecondVersion; 09-27-2005 at 08:11 PM.
Eric is offline  
Old 09-27-2005, 04:47 PM THREAD STARTER               #7 (permalink)
New Member
Join Date: Mar 2005
Posts: 9
j0n87 is an unknown quantity at this point
 



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?
j0n87 is offline  
Old 09-27-2005, 05:41 PM   #8 (permalink)
Account Closed
Join Date: Jul 2005
Posts: 102
Archimed will become famous soon enoughArchimed will become famous soon enough
 



kind of, i am budling like that... www.ipgfx.net/test/index1.php
Archimed is offline  
Old 09-28-2005, 04:30 AM   #9 (permalink)
NamePros Regular
 
NuPagady's Avatar
Join Date: Jul 2005
Location: Lithuania
Posts: 482
NuPagady is on a distinguished road
 



Originally Posted by j0n87
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 Code:
<?php include("head.php"); ?>

<?

include_once("content.php");

switch (
$_GET["page"]) {
????: NamePros.com http://www.namepros.com/showthread.php?t=122733
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"); // 1. script will include header

switch ($_GET["page"]) { // script will check variable "page" from the link
case 1: // If the link is index.php?page=1, it will include "content.php"
   include("content.php");
   break;
case 2: // If the link is index.php?page=2, 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

?>
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.
????: NamePros.com http://www.namepros.com/showthread.php?t=122733


P.S. sorry for my broken english
Attached Files
File Type: zip include.zip (1.3 KB, 3 views)
NuPagady is offline  
Old 09-28-2005, 05:16 AM THREAD STARTER               #10 (permalink)
New Member
Join Date: Mar 2005
Posts: 9
j0n87 is an unknown quantity at this point
 



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 by j0n87; 09-28-2005 at 05:29 AM.
j0n87 is offline  
Old 09-28-2005, 05:54 AM   #11 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by j0n87
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 Code:
<?

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
????: NamePros.com http://www.namepros.com/showthread.php?t=122733

?>
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Totorial - Adding Music to your Site abacomedia Webmaster Tutorials 7 08-27-2005 09:12 AM
Centering PHP included files FreeBaGeL Programming 1 07-16-2005 12:01 PM
Using Music on your Site - WAV, MP3, MIDI, Flash? abacomedia Web Design Discussion 1 05-20-2004 02:04 PM
3 Char Domain & Great Domain Include Website For Sale! eebay Domains For Sale - Make Offer 4 12-10-2003 12:43 PM
Include external files with out the use of server side technology deadserious CODE 2 12-08-2002 11:43 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:55 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger