Friday 16 September 2011

How do I put multiple pages in index.php?

I want to make a website, but instead of having loads of pages e.g index.php, gallery.php news.php, etc, etc I can have everything in index.php and use PHP and javascript to change the content of the page. I have managed to get this partially working by using a form to post a variable, but I would like the links to change the content to be an anchor tag. Code examples would be great. ThanksHow do I put multiple pages in index.php?The include function of PHP will basically load another page into the current page. I'm not sure if that is the solution you are looking for since you will still have to code the other pages.



The only way your idea is possible is to code the page to where it is 100% dynamic based off of some input parameter on the URL. Doing this will require you to have a bunch of if/elses in your PHP code and you would still be coding the page inside each of the if/else blocks. This will make one very long and hard to manage index.php file.



That being said, if you are wanting to hide the directory structure of your site by only showing the index.php page in your URL, you may want to look at the PHP include idea. You will have to code the other pages but you can include each of these pages inside of a DIV in your HTML code. You can then use javascript to show and hide certain DIV's based on what the user clicked on.



Here is a quick example of how to show and hide DIV's:

Hide a Div:

document.getElementById('YourDivName')鈥?= 'hidden';

Show a Div:

document.getElementById('YourDivName')鈥?= 'visible';
How do I put multiple pages in index.php?
%26lt;?php

include(%26quot;filetoinclude.php%26quot;);



?%26gt;



People usually do this with menus or footers on their pages. Personally it's the best solution



if i misunderstood any part of your question just update your question and ill try and help.
How do I put multiple pages in index.php?
STOP, why would you want to do this. Do you even want to be ranked with Google at all? Because you will have terrible rank if you do this. You NEED separate pages.
You could build a flash website or do this with Ajax.