newnewbie Posted April 8, 2010 Share Posted April 8, 2010 I have a page in which i require another page. For instance I want a variable (the page title) in 'main.php' to pass to the required page (template). The reqired page contains my header, nav, footer, etc. So, in main.php i have: <?php require_once("template.php"); ?> <?php $page_title = 'Home'; ?> In the header section of template.php, I want to use the variable $page_title to print as Home. Something like <title>print $page_title</title> This can't be that difficult, but check out my ID...newnewbie! Thankx in advance as always! Quote Link to comment https://forums.phpfreaks.com/topic/198000-pass-a-variable-to-a-required-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2010 Share Posted April 8, 2010 As long as the variable has a value at the time the code in template.php references it, what you are doing will work. Quote Link to comment https://forums.phpfreaks.com/topic/198000-pass-a-variable-to-a-required-page/#findComment-1038968 Share on other sites More sharing options...
newnewbie Posted April 8, 2010 Author Share Posted April 8, 2010 All that time and all I had to do was put the variables before the require code. This worked and actually solved two of my problems I have been teaching myself php for a couple of weeks...sooo much to learn. Thank you for helping my day be much brighter! Quote Link to comment https://forums.phpfreaks.com/topic/198000-pass-a-variable-to-a-required-page/#findComment-1038978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.