Jump to content

Archived

This topic is now archived and is closed to further replies.

r22pl

Outside variable to work with include function

Recommended Posts

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

common.inc.php includes all of my includes and classes, such as [b]page.inc.php[/b]:

[code]
<?php
session_start();

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

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

Share this post


Link to post
Share on other sites
Yea there's a little trick to that:

[code]

<?php
session_start();

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

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.