• 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

¿php question?

TheRunes

New Member
Is it possible to have a website made in php that loads each page from a txt file?
What i mean is:
the main page loads (index.php)
then the user clicks a link... and index.php gets reloaded with the content from a txt file.

I believe it can be done...
I dont know how...
I have basic understanding of php...
the majority of my knowledge is include and require functions...
if my idea is possible... can someone help me make it reality?
 
Sure, just include the content's of a text file in the index script:

PHP:
include("textfile.txt")

You may also use SSI or File Scripting.
 
Code:
<?
if (!$QUERY_STRING) {
include("pages/home.txt");
} else {
include("pages/$QUERY_STRING.txt");
}
?>

in this example, all your .txt files are in a directory called /pages/



if you just type in your domain, and inex.php is called, it will load by default /pages/home.txt



if you link to /index.php?freeware it will load /pages/freeware.txt



this way, you don't have to specify every .txt file in your directory. whenever one's added or deleted, just link to it, no setting it up in the script itself.



it might be wise as well to use .php files as opposed to .txt files. same thing, just a different extension. might work faster with a .php index file, i'm not sure, but that preobably wouldn't be noticeably faster anyhow.



and use the index file to store your header and footer, so changes to your site's layout can be changed sitewide by editing just the index file:
Code:
<html>
<head>
<title>My Homepage</title>
</head>
<body>

<?
if (!$QUERY_STRING) {
include("pages/home.php");
} else {
include("pages/$QUERY_STRING.php");
}
?>

</body>
</html>
and store the .php files in a directory called /pages/, or whatever you want...


hope that helps. it works exactly the way you want it to... i use this setup with http://www.joebluhm.com [click "contact", it's the only section finished right now]
 
Last edited:
Thank you keith... that is exactly what I was looking for too... I think I am going with the whole dreamweaver template thing though now.
 
Back
Top