• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

phpinclude

i want something like this site...
http://www.xzon.net/
hmm..i don't know how to explain it:confused2...i want something where i just make the main page with the layout, and all the other links are .txt files...so when i edit my layout i don't have to change all the other files....something like frames....
 
Last edited:
Make a page called "index.php". Make it completely normal, just straight html, it will be the layout of your site. Then, in the area you want the content, put:

PHP:
<?
if(!file_exists("$page.txt")){
$page = "index";
}
include("$page.txt");
?>

So, if someone just goes to http://yourdomain.com/ , it will include "index.txt". And if they go to http://yourdomain.com/index.php?page=notarealpage , then "index.txt" will still be included. But if they go to http://yourdomain.com/index.php?page=links , and "links.txt" is a real file, it will include "links.txt".
 
hm..i still don't get this :mad:
ok..so on the index.php page, which will be my layout...where i want the content to be, i put..
PHP:
<?
if(!file_exists("$page.txt")){
$page = "index";
}
include("$page.txt");
?>

what do i do to the other pages? what do i put in the txt file?
 
Put html in the text file. You don't need the <html> or <body> tags, just start with the heading or whatever is different. So, in "index.txt", put something like:

Code:
<h2 align="center">Welcome</h2>
<br>
Welcome to my site.  Blah blah blah blah blah.
If you would like to contact me, <a href="index.php?contact">Click Here</a>

And in contact.txt:

Code:
<h2 align="center">Contact</h2>
<br>
Fill in the following for and hit submit:

<FORM action.....



</FORM>
 
jeese, ya'll make this more complicated than it is and confuse the man. Its simple, I use it myself.

make index.php a HTML formated page, then where u want the information included do something like this:

PHP:
<?
if($page == "") {

echo "Default crap or include your default page";
} else {

$include = "$page.txt"; //or w/e extention u want
if(file_exists("$include") {
include("$include");
}
else { echo "page aint there! AGGHH"; }

}

?>

its not rocket science guys, so dont explain it like it is.
 
Well, I agree, I didn't explain myself very well...and like you said, it's not rocket surgery . In all fairness to myself, your code was 9 lines, mine was 4.
 
rocket surgery? lol, kinda has that ring to it, lol. Yeah, tru, the fewer the lines the better. But what if they goto index.php directly? You'll get a cool looking error that says "Error including http/directory/public_html/.txt" lol, thats what the extra 5 lines of mine are to prevent, eitherway they both work almost the same.
 
Actually, if "$page" is null, it will check if ".txt" exists, and since it does not, it will include "index.txt".
 
Here's my system...

PHP:
<?php

/////////////////////////////////////
// This is 'include.php'
/////////////////////////////////////

$page[0] = "your_default_page.txt";
$page[1] = "another.txt";
$page[2] = "and_another.txt";

?>

Code:
<!-- This is you template with all of your HTML etc. -->
<!-- This should be 'index.php' or something
<?php include("include.php"); ?>
<html>
<head>
.
.
.
<?
if(!isset($p))
  include($page[0]);

else
  include($page[$p]);
?>
.
.
.
</html>

Then whenever you make a link, put the page in include.php and make the link to 'index.php?p=' then the page number according to the indexing in include...
:classic2:
 
That also works, but requires more effort. I don't see why people make things harder than they have to be.
 
It isn't hard, and this way you aren't limited to a couple pages - your whole site uses it, not just 'index' or whatever. Let me in on the less effort way and mabe I'll use it.
 
Originally posted by Christopher
It isn't hard, and this way you aren't limited to a couple pages - your whole site uses it, not just 'index' or whatever. Let me in on the less effort way and mabe I'll use it.

the other examples we´ve seen in this thread are actually less limited than yours and require less effort like Canuckkev said...

if you don´t understand how it works it looks for a file with the name of the value of $page and the extention .txt (and if it doesn´t exist it includes index.txt) so you don´t have to specify all the files that can be included like in your script...
 
Originally posted by Christopher
It isn't hard, and this way you aren't limited to a couple pages - your whole site uses it, not just 'index' or whatever. Let me in on the less effort way and mabe I'll use it.
But then there isn't a default page compared to the "traditional" script.
 
Back
Top