Forum Moderators: phranque

Message Too Old, No Replies

New to PHP

...need help on multiple files in one file

         

InfaredFog

1:18 am on Sep 21, 2005 (gmt 0)

10+ Year Member



So I've done basic web page design for a while now and finally got around to having a friend with limited PHP knowledge help me set up some basic "click to change information" code. One thing I would like to be able to do, however, is to have all the different "pages of information" be in one .html file (or can they be in .php files too?) so I don't have multiple files cluttering up my editor etc. I'm not even sure if this is possible, I've tried looking a bit, but if it is I would really appreciate some help (as well as any other handy PHP tricks :P) Thanks in advance guys,
Ben

mcavic

3:36 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anything is possible in PHP. :) Are you saying that you want multiple Web pages that appear as multiple pages to the user, but are all stored in one file?

Yes, you can do that, but it's generally less organized. You'd also need to use a variable in the url so that the server would know which page to show. The url would look like www.example.com/index.php?c=1 and in the PHP script, the "1" would be stored in the variable $_GET['c']. The "?c=1" would make the pages much less attractive to search engines.

grandpa

8:15 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe you are asking about a page where a user makes a choice, then another set of options is displayed... all on the same page, with different screens displayed where appropriate? Yes. That is also possible. I do it all the time.

And, while they look like normal html pages to the user, they are really php scripts in disguise. Apache's Mod_Rewrite is your friend in that situation.

Almost forgot.. Welcome to WebmasterWorld InfaredFog.

mcavic

2:42 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, mod_rewrite can help there too, but what you really need is a variable to tell the php script what to do.

InfaredFog

4:04 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



Ok what I mean (and these pages wouldn't really have to be search-engine friendly, I don't need huge traffic) is right now when I click a link the main body of information on the page changes, and is gotten (from PHP) another file, for example "contact.html" or something if you click on the contact link. Well each one of these links that changes the information on the page is a seprate file. Can I combine all these files?

<?
if (!(array_key_exists("module",$_REQUEST)))
{
$module="home";
$l="?";
}
else {
$module=$_REQUEST["module"];
}
?>

and

<a href="?module=home">home</a> ¦
<a href="?module=aboutus">about us</a> ¦
<a href="?module=howtojoin">how to join</a> ¦
<a href="?module=ourteam">our team</a> ¦
<a href="?module=forum" target="_blank">forum</a> ¦
<a href="?module=partners">partners</a> ¦
<a href="?module=resources">resources</a> ¦
<a href="?module=portfolio">portfolio</a>

is the main PHP part in my site.