Jump to content


Photo

Outside variable to work with include function


  • Please log in to reply
2 replies to this topic

#1 r22pl

r22pl
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 March 2006 - 09:52 PM

The way I have my index.php file start is:
<?php
$pagename = "Home";
require_once("include/common.inc.php");
page_header();
?>

common.inc.php includes all of my includes and classes, such as page.inc.php:

<?php
session_start();

// Start Header
function page_header() {
?>
    
    <?php
    echo "$pagename";
    ?>

I can't get it to recognize the variable $pagename, which I need for the title, nav, etc.

#2 Steveo31

Steveo31
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSan Jose, CA

Posted 07 March 2006 - 10:07 PM

Yea there's a little trick to that:


<?php
session_start();

// Start Header
function page_header(&$pagename) {
  echo "$pagename";
}

The & sign means its passing by reference or something like that. Check the manual.

#3 r22pl

r22pl
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 March 2006 - 10:11 PM

Thanks, that worked!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users