PDA

View Full Version : passing variables to PHP script?



LastActionHero
September 16th, 2001, 05:25
ok, I have had enough of updating all individual pages. Now I'm moving to PHP based template system. The rest I have figured out... and I have a script which does all the work.

It includes the header and footer which remain the same on all the pages and the body changes according to what i want. The script just has three include statements. Now I need to pass the name of the page i need to include in the body like this ....

domain.com/page.php?index.html

Now how do i read the index.html part in? I need to store it in a variable and call it in the include statement

<? include(variable); ?>

Satelk
September 16th, 2001, 12:36
Try this:

<?
if(isset($QUERY_STRING))
{
$temporary_array = explode("&",$QUERY_STRING);
$page = $temporary_array[0];
unset($temporary_array[0]);
}
else
{
$page = "";
}
include($page);
?>

Hope this helps!

Canuckkev
September 16th, 2001, 12:51
Yeah....that should work. Or, can't you just use a variable in a php script right from the query? Like if you do http://www.blahblah.com/index.php?page=home , now can you just use the variable "$page", without defining it, cause it's value is from the query? I think that's how it works. If not, that will explain why I can't get my php scripts to work.

LastActionHero
September 16th, 2001, 13:00
If you pass a variable as the query sting I think you do need to declare it in the script. When you pass a value it is automatically initialised.

Thanks satelk. But I want only one variable to be passed so the array is not required right? Also shouldn't the explode string be ? if i'm passing something like this -> domain.com/file.php?blah.htm

Satelk
September 16th, 2001, 13:36
You're right, you don't really need the array. You only need this:


<? include($QUERY_STRING); ?>


I found the other code in a script I had, didn't really looked what parts were needed.

LastActionHero
September 17th, 2001, 03:10
Thanks Satelk.