Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Two questions here. First, I want to be able to display an entire website from one PHP page, with the page serving different sections depending on a variable passed from the browser. For example, you're on the "Home" page, and you click "Contact us". I want the original page to also serve the info for the new page instead of creating five different pages doing five different things.

So the question is, how do you pass a variable through a URL link that tells the page reload itself with different parameters?

And the second question is, is this a good idea? I'm not even sure if this is a good idea. What are the pros and cons to doing it this way versus creating a different page for every page on the site? I'm just starting with PHP, so my experience is limited.

Thanks in advance.
Posted

1 solution

I'm not a PHP person, and have only a little PHP experience but:

It is possible to route it all through one page. A well-established pattern to help do this is MVC[^]. There are good MVC frameworks out there apparently (Google "PHP MVC"). Or you can write your own http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/[^] if you really want to get to grips with this as a problem.

You can use query strings in the URL to pass information, or create generated JavaScripts to server up the correct view and do stuff.

To your second question, it is matter of horses-for-courses. If you just want several pages with different content, then I'd answer no. If you have lots of process-specific stuff (like Wizards) where the MVC pattern is a good fit, or you are just doing it to see how it would work, then I'd say yes.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 7-Jan-11 15:27pm    
Good answer! 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900