Outside variable to work with include function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r22pl
Forum Newbie
Posts: 6
Joined: Tue Mar 07, 2006 3:45 pm

Outside variable to work with include function

Post by r22pl »

The way I have my index.php file start is:

Code: Select all

<?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:

Code: Select all

<?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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

lookup the "global" keyword, however I'd recommend passing $pagename to the function.
r22pl
Forum Newbie
Posts: 6
Joined: Tue Mar 07, 2006 3:45 pm

Post by r22pl »

Thanks, I passed $pagename to the function and it worked
Post Reply