Passing variables to a function within an included file
Posted: Mon Feb 17, 2003 11:41 am
Hello Dear People,
Having searched for hours on the forum, I am tearing my hair out. Please help.
My issue is that I am trying to pass a variable to an function defined in an included script.
My function is GenerateHeader() that is defined in the file common.php.
GenerateHeader() contains html for my site logo and menu bar.
The main page for my site, home.php is fed the value of $key from the URL. Home.php includes common.php to generate the top half of the page.
Is there any way to pass $key to the GenerateHeader() function in the included common.php?
Here is some code to illustrate.
home.php -- $key is given a value from the URL ie: home.php?key=value
This is the function in common.php - I would like the value of $key to be appended to the end of each link because the scripts (page2.php, page3.php, etc) will use $key in forms and things like that.
I really hope someone can help me.
Thanks in advance.
Having searched for hours on the forum, I am tearing my hair out. Please help.
My issue is that I am trying to pass a variable to an function defined in an included script.
My function is GenerateHeader() that is defined in the file common.php.
GenerateHeader() contains html for my site logo and menu bar.
The main page for my site, home.php is fed the value of $key from the URL. Home.php includes common.php to generate the top half of the page.
Is there any way to pass $key to the GenerateHeader() function in the included common.php?
Here is some code to illustrate.
home.php -- $key is given a value from the URL ie: home.php?key=value
Code: Select all
<?
include("common.php");
GenerateHeader();
?>
<html>
<head>
</head>
<body>
//HTML for the page content.
<?=$key?>
</body>
</html>Code: Select all
function GenerateHeader() {
?>
<html>
<head>
</head>
<body>
//html for menu bar and top bar ie:
<a href="page2.php?key=<?=$key?>">Page 2</a>
<a href="page3.php?key=<?=$key?>">Page 3</a>
</body>
</html>Thanks in advance.