Passing variables between same script
Moderator: General Moderators
Passing variables between same script
Okay I am working on my first site made entirely in php and I would like to have the entire site in one script. I want it too start by displaying one page and when a person clicks on a link I want it too pass a variable so the script and it use that variable to decide which part of the script to do.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
http://www.domain.com?foo=bar
and you can access the variable $foo by using
echo $_GET["foo"] // returns bar
and you can access the variable $foo by using
echo $_GET["foo"] // returns bar
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Just as an aside....
In most cases coding an entire site with one PHP script is not efficient. The entire PHP code needs to be loaded and processed.
Splitting the php scripts into useable components not only decreases the time it takes to serve the web page it makes the code more maintainable.
If you have not already seen them look up the commands include and require in the php manual and only load the code you need to.
The key to good, maintainable code is a proper, efficient design. It may seem to be an overhead when building the system but it saves lots of time later.
In most cases coding an entire site with one PHP script is not efficient. The entire PHP code needs to be loaded and processed.
Splitting the php scripts into useable components not only decreases the time it takes to serve the web page it makes the code more maintainable.
If you have not already seen them look up the commands include and require in the php manual and only load the code you need to.
The key to good, maintainable code is a proper, efficient design. It may seem to be an overhead when building the system but it saves lots of time later.
Normally I would say you were right but since this is not a large site, just a website about myself, and only one part of the site will be changed from page to page( ie keeping the top pannel and the side links) and only changing the content part I figured the best part would just put the different content pages into different variables and load them in as needed.