PDA

View Full Version : phpinclude



Resshin
August 4th, 2002, 13:43
how do i use PHPinclude?

yarassa
August 4th, 2002, 16:34
what do you mean? if you mean include ("/home/sth/else"); here it is!!!

Resshin
August 4th, 2002, 16:58
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....

Canuckkev
August 4th, 2002, 18:18
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:



<?
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".

Resshin
August 4th, 2002, 18:26
so, if someone wants to go to the page with the content...will it be
http://yourdomain.com/index.php?page=links ?
do i have to add the .txt extension the the url?

Resshin
August 5th, 2002, 21:18
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..

<?
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?

Canuckkev
August 5th, 2002, 23:25
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:



<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:



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

<FORM action.....



</FORM>

rapmaster
August 6th, 2002, 01:26
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:




<?
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.

Canuckkev
August 6th, 2002, 01:46
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.

rapmaster
August 6th, 2002, 01:54
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.

Canuckkev
August 6th, 2002, 12:54
Actually, if "$page" is null, it will check if ".txt" exists, and since it does not, it will include "index.txt".

Christopher
August 6th, 2002, 13:57
Here's my system...


<?php

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

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

?>


<!-- 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:

Canuckkev
August 6th, 2002, 18:20
That also works, but requires more effort. I don't see why people make things harder than they have to be.

Christopher
August 6th, 2002, 21:41
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.

spork
August 7th, 2002, 06:27
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...

The Red Guy
August 7th, 2002, 08:35
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.