monkeybidz Posted April 9, 2009 Share Posted April 9, 2009 I am using: header.php index.php footer.php All in one instance. I need to get the variable $title from the index to echo in header. How do I get this to the header file. I tried simply: echo $title; in the header, but it does not call it. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/153397-solved-get-a-variable-from-a-current-page/ Share on other sites More sharing options...
MadTechie Posted April 9, 2009 Share Posted April 9, 2009 Options #1 create another file called global.php <?php $title = "My Title"; ?> then add include "global.php"; at the start of header.php & index.php #2 Store it in a session ie <?php start_session(); //at the top $_SESSION['title'] = $title; ?> EDIT: PS this is one of those questions where it may help us if we know why you want! Quote Link to comment https://forums.phpfreaks.com/topic/153397-solved-get-a-variable-from-a-current-page/#findComment-805924 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 All in one instance. I need to get the variable $title from the index to echo in header. How do I get this to the header file. I tried simply: echo $title; in the header, but it does not call it. Because that's entirely a different file which is obviously out of the scope. Like MadTechie said you should store it in a session variable so you can easily pass it among pages. This will avoid including files. Quote Link to comment https://forums.phpfreaks.com/topic/153397-solved-get-a-variable-from-a-current-page/#findComment-806006 Share on other sites More sharing options...
monkeybidz Posted April 10, 2009 Author Share Posted April 10, 2009 I just used a query in the header file and that did it. You guys have been very helpful. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/153397-solved-get-a-variable-from-a-current-page/#findComment-806072 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 I just used a query in the header file and that did it. You guys have been very helpful. Thank you! Hmm, not sure how that solved you problem because your question was (not really a question): I need to get the variable $title from the index In any event, glad you resolved everything. Quote Link to comment https://forums.phpfreaks.com/topic/153397-solved-get-a-variable-from-a-current-page/#findComment-806078 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.