Php: Variable Help
- inVicious
-
inVicious
- Member since: Jan. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
I've been messing around with SSI, and Im using a variable with my include
<?php include ("$body"); ?>
so on the menu file I have
$body = "body.php"
When I upload the site it works fine,
but what I want to know is how to make a link change the variable like
make the link change from
$body = "body.php" to $body = "contact.php"
sorry if its hard to understand I really don't know how to word this
- inVicious
-
inVicious
- Member since: Jan. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
- harryjarry
-
harryjarry
- Member since: May. 15, 2005
- Offline.
-
- Forum Stats
- Member
- Level 57
- Blank Slate
Is something like this what you are looking for?
<?php
$include = $_GET['include'];
$body = "main";
if(isset($include)) {
$body = $include;
}
include("./$body.php");
echo 'Flash';
?>
Then with each link just make is "?include=Category" and it will include whatever you put for the category then add .php to it.
Although if you wanted to include html files you would have to change the script to make the "?include=whatever.extension" to include whichever file, but you would also have to take .php out of the include.
- inVicious
-
inVicious
- Member since: Jan. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
see I have 4 files index.php, header.php, menu.php, and body.php, (I know you know how SSI works Im just explaining how I have it, in the index I have the includes,
in the index for the body I have <?php include ("$body"); ?> and &body is the variable,
and inside the menu file I have $body = "body.php" and when I check the browser it works,
I just w don't know how to make a link like home change the variable, I'm sorta still liearning php sorry for my lack of knowledge
- harryjarry
-
harryjarry
- Member since: May. 15, 2005
- Offline.
-
- Forum Stats
- Member
- Level 57
- Blank Slate
Hehe it is alright, everyone has to start somewhere ;).
You can change the includes with the $_GET method.
Now let's break down the code
<?php
$include = $_GET['include'];
This defines $include as whatever the url makes the include value with $_GET, such as "index.php?include=home" that would make the variable $include have the value home.
You can switch it to whatever you would like it to include as well.
$body = "main";
This sets the $body variable to have a default, which is "main" or you can change it to body, or whatever you want the page to include when someone first goes to the page without clicking any links.
if(isset($include)) {
$body = $include;
}
This first checks if there is "?include=whatever" in the url, if it isn't there it will keep $body as "main" or whatever you define it to have as default.
include("./$body.php");
This is the include section, it will include whatever $body is defined as, and it adds on .php so you don't have to have .php in the "?include=whatever".
echo 'Flash';
I meant to make this easier on this part but forgot that it would be turned into a link.
It should look something like:
echo '<a href="?include=flash">Flash</a>';
You can make the link have whatever you want after "?include=" as that will be what file you want to include into your page.
You could have "?include=menu" or whatever else you might want to include onto the page.
?>
End of code :P.
I hope this is what you are looking for :).
- inVicious
-
inVicious
- Member since: Jan. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate


