intothefray2007 Posted August 29, 2008 Share Posted August 29, 2008 Hello everyone! Let's start off by saying that I don't have years of experience with PHP programming, though I do understand the language. I have an index.php page that includes the following: --------------------------------------------------------------------- <?php include_once('includes/header.php'); ?> <?php include_once('includes/menu.php'); ?> <?php include_once('includes/side.php'); ?> <?php if (isset($_GET['pg']) && $_GET['pg'] != "") { $pg = $_GET['pg']; if (file_exists('pages/'.$pg.'.php')) { @include ('pages/'.$pg.'.php'); } elseif (!file_exists('pages/'.$pg.'.php')) { echo 'The page you are requesting does not exist'; } } else { @include ('pages/home.php'); } ?> <?php include_once('includes/footer.php'); ?> --------------------------------------------------------------------- After my includes load, the middle part checks which ?id's been sent through the URL so that it loads the appropriate file in my /pages directory (such as about.php). In each of these subpages, I set the "$pagetitle" variable that is called (echo) in header.php. Problem is... I'm calling $pagetitle (in header.php) BEFORE the subpage is called, so the variable gets missed... How do I go about changing the page title AFTER it is originally parsed? Also, I was trying to implement a breadcrumb script in menu.php but I'm not getting anywhere because of this same problem (the breadcrumb script loads before the subpage does). Anyone have a clue on how I can get around this? Thank you! Link to comment https://forums.phpfreaks.com/topic/121884-loading-variables-after-theyve-been-parsed/ Share on other sites More sharing options...
Fadion Posted August 29, 2008 Share Posted August 29, 2008 You can't do much on this as long as you use this system, which is quite ok. What I would do is change the header.php code to display the right title. Let's go for an example: header.php <?php $urls = array('home'=>'This is the home page', 'about'=>'Wanna know about me?'); if(isset($_GET['page'])){ if(array_key_exists($_GET['page'], $urls)){ echo '<title>' . $urls[$page] . '</title>'; } else{ echo '<title>Page does not exist</title>'; } } else{ echo '<title>' . $urls['home'] . '</title>'; } ?> Basically you print the title independent from the included file, but with the proper validation so they match. Hope this gives you the right idea. Link to comment https://forums.phpfreaks.com/topic/121884-loading-variables-after-theyve-been-parsed/#findComment-629184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.