dylandcor Posted February 24, 2009 Share Posted February 24, 2009 I want to dynamically generate content based on where a user is in my site. I set a variable $page in the index page before I included header.php with the following code in it. The header.php cannot seem to find the $page variable. Any help would be greatly appreciated. index.php <?php $page="index"; include ("header.php); ?> header.php <?php if ($page=="index"){ $html="<b>WELCOME TO THE INDEX"; $htmlsidebar=""; }else{ $html="<tr>"; echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/ Share on other sites More sharing options...
gevans Posted February 24, 2009 Share Posted February 24, 2009 there was a typo in index.php; <?php $page="index"; include ("header.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/#findComment-770318 Share on other sites More sharing options...
rhodesa Posted February 24, 2009 Share Posted February 24, 2009 the concept of your code is fine...there are some syntax errors though <?php $page="index"; include ("header.php"); ?> <?php if ($page=="index"){ $html="<b>WELCOME TO THE INDEX"; $htmlsidebar=""; }else{ $html="<tr>"; } echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/#findComment-770319 Share on other sites More sharing options...
dylandcor Posted February 24, 2009 Author Share Posted February 24, 2009 Thank you for your quick replies! I have done what you both said and cleaned my code up. It is still however... Not working. I had the index echo the $page variable and it does do the correct one. index.php <?php $page="index"; echo $page; include ("http://www.mysite.com/header.php"); ?> I then have the header.php echo the $page variable which does not work. header.php <?php if (!isset($page)) { echo "DOES NOT EXIST"; #I am getting this when I load the page which proves that the variable does not exist? } #Start Content Here if ($page=="index"){ $html="Index"; $htmlsidebar=""; }else{ $html="Other Site"; } echo $page; echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/#findComment-770328 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 You are including a URL, you have to include the file from the server. include ("header.php"); Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/#findComment-770332 Share on other sites More sharing options...
dylandcor Posted February 24, 2009 Author Share Posted February 24, 2009 Thank you so much all of you for all your help. Problem Solved Quote Link to comment https://forums.phpfreaks.com/topic/146726-solved-passing-a-variable-to-another-page/#findComment-770337 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.