Page 1 of 1
A little bit of help please.
Posted: Wed Jul 24, 2002 5:53 pm
by Goffie
Hello,
I don't know much about php at all but I know the server that I'm running my website on supports it. I was wondering if it would be easy to use php to take a text file and implement it into my html pages.
I want the php code to be able to take it off the file server and then place it into my html so that updating a sidebar won't involve updating 20 different pages but instead just 1 txt document. Is this possible and how would I go about doing it?
Posted: Wed Jul 24, 2002 6:10 pm
by gnu2php
Sure. Just place <!--sidebar--> in your HTML pages, and then from PHP replace <!--sidebar--> with the contents of the text file.
The more common approach, however, is to convert your HTML files to PHP and just do
include('sidebar.inc')
If you don't know how to do this, let me know.
Posted: Wed Jul 24, 2002 6:46 pm
by Goffie
Sadly I don't. I'm not exactly sure if that would do what I want but I think I can explain this better if I was to word it this way.
I have sidebar.txt, that file contacts <a href="blahblahblah.html"> Blah </a> and so on.
Then on the index.html page in a cell on the main table I want to inset all the contents of sidebar.txt, if possible with just one command that brings it from the source.
Now if this <!--sidebar--> does that where does it know to load the text file from?
ok here
Posted: Wed Jul 24, 2002 6:52 pm
by pb2ya
the code is this:
-or-
use iframes if you dont know php.
Posted: Wed Jul 24, 2002 7:46 pm
by gnu2php
The only way to do it, I think, is to set all your HTML files to use PHP, and place
include('sidebar.txt') where you want the sidebar.
Or you could have a "central" PHP file that sends out all the HTML files. You would use it like this
index.php?file=mypage.htm. You can go this route by placing the following in the index.php file:
Code: Select all
<?
// This prevents things like "index.php?page=../../etc/passwd"
$html_files = array('mypage.htm', 'mypage2.htm');
if (!in_array($_GETї'page'], $html_files))
die("Invalid page $_GETїpage]");
// First get the HTML page
$fp = fopen($_GETї'page'], 'r');
$data = fread($fp, filesize($_GETї'page']));
fclose($fp);
// Then get the sidebar
$fp = fopen("sidebar.txt", 'r');
$sidebar_data = fread($fp, filesize("sidebar.txt"));
fclose($fp);
// Finally, insert the sizebar
print str_replace('<!--sidebar-->', $sidebar_data, $data);
?>