|
Author |
Message |
Zealot Zachary
Junior WebHelper
Joined: 28 Dec 2004
Posts: 4
|
Posted:
Tue Dec 28, 2004 10:57 pm (19 years, 4 months ago) |
|
Hello! as wel as new to the site, I'm also new to php. Riht now while trying to expand my knowledge im trying to create a website built on php using only one page, index.php. The over all idea would be that that would be the layout and the content would be a text or php file that would loaded by include="&content.txt" and the &content should be modified when clicking on a link, which I have no idea how to code, please help me!
edit:nevermind, i figured it out the code i used was
for the link
Code: | <a href="index.php?content=drawing"> |
for the content
Code: | <?php
if ($content == "drawing")
{include('drawing.txt');}
else
{include('index.txt');}
?> |
for anyone that cares
edit2: is there anyway to do this without constantly updating the site, as in variable read by include |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Wed Dec 29, 2004 11:58 am (19 years, 4 months ago) |
|
This should do it:
include($content . ".txt");
although it would probably be an idea to check whether such a file actually exists incase the query string is accidently altered/missing etc. Give this a go...
Code: | $filename = (isset($_GET['content'])) ? $_GET['content'] : "index";
$include_file = $filename.".txt";
if(file_exists($include_file))
{
include($include_file);
} else {
echo "Sorry, there is no page of that name.");
} |
Assuming I didn't make any mistakes this should do the following:
Line 1 is an IF statement that checks if the $_GET['content'] variable has been set. If it hasn't the $filename variable is set to 'index', if it has $filename is given the contents of the $_GET['content'] variable. This just lets us set the default for when there is no query string (i.e. the homepage)
next we join (or concatenate) the filename to the .txt extension this is done with the fullstop.
Then the main if statement checks that the file exists, if it does it is included. If it doesn't an error message is displayed. You could just include the index at this point instead. |
|
|
|
|
Zealot Zachary
Junior WebHelper
Joined: 28 Dec 2004
Posts: 4
|
Posted:
Fri Dec 31, 2004 8:17 am (19 years, 4 months ago) |
|
thank you very much for your knowledgable and explanational reply! |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Fri Dec 31, 2004 10:23 am (19 years, 4 months ago) |
|
No probs, did it work OK? |
|
|
|
|
Zealot Zachary
Junior WebHelper
Joined: 28 Dec 2004
Posts: 4
|
Posted:
Sat Jan 01, 2005 11:23 am (19 years, 4 months ago) |
|
unlike those newbs who just copy and paste, I actually tend to try and udnerstand what info im receiving, and after i found your lil coding mistake, it worked like a charm
Code: | echo "Sorry, there is no page of that name."<!-- SCRIPT ERROR!!!!!!--!>)<!--END SCRIPT ERROR OF TERROR--!>; |
|
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Sat Jan 01, 2005 4:40 pm (19 years, 4 months ago) |
|
As well as telling the user the file wasn't found, it is probably a good idea to set the HTTP status to 404:
Code: | header('HTTP/1.0 404 File Not Found'); |
|
________________________________ It's turtles all the way down... |
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Sat Jan 01, 2005 6:46 pm (19 years, 4 months ago) |
|
Zealot Zachary wrote: | unlike those newbs who just copy and paste, I actually tend to try and udnerstand what info im receiving, and after i found your lil coding mistake, it worked like a charm
Code: | echo "Sorry, there is no page of that name."<!-- SCRIPT ERROR!!!!!!--!>)<!--END SCRIPT ERROR OF TERROR--!>; |
|
ahh, thats because I pasted from my own site, where I have a function to display the error message... I guess I missed that when I reformatted into an echo |
|
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.155723 seconds :: 19 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |