/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] txt files and index.php

Alright so just about 3 years ago I use to know how to import .txt files into my index.php file. For example, you go to my website and it goes to the index.php file and it displays the home.txt file. Then when you click About us or something else, it uses the index.php file and loads the aboutus.txt file and the URL.link would be index.php?=aboutus. This way, when I edit my index.php file, it applies it to all my pages. So my public_html directory would consist of one index.php file with a bunch of .txt files (about.txt, home.txt, contact.txt, etc)

Now, I don’t recall what code I used in my index.php file. Any help would be much appreciated, Thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pcthugOct 26.2006 — This will do what you want. Note any text files that you wish to be served must consit of only [I]word[/I] characters (alphanumeric and underscores).[code=php]<?php
/* index.php */
define('dir_root', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('def_page', 'home');

// set default page
$page = def_page;

// fulfill page request if present
if(isset($_GET['page']))
{
$page = strtolower(preg_replace('/([^w]+)/', '_', $_GET['page']));
$page = trim($page, '_');
}

// build filename
$filename = dir_root . "/$page.txt";

// if text file is not readable reset filename variable
if(!@is_readable($filename))
$filename = dir_root . def_page . '.txt';

// if inclusion of the text file fails trigger an error page
if(!@include $filename)
{
@header('HTTP/1.0 500 Internal Server Error');
exit('<html><body><h1>Oops...</h1><p>An unexpected error has occured.</p></body></html>');
}
?>[/code]
To access a text file use the following format:
<i>
</i>http://yourdomain.com/index.php?page=[color=red]text_file_filename[/color]
Copy linkTweet thisAlerts:
@parnesonauthorOct 26.2006 — Thank you soo much!
×

Success!

Help @parneson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...