3 replies [Last post]
roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

I swear this worked before but maybe not with PHP5??

Ok so here's my example. I'm making a header that I want to include on every page. I want it to grab the page_title variable and display it using the included header. I have two files header.php and index.php

header.php

<?php echo $page_title; ?>

index.php

<?php
global $page_title;
$page_title = "This is a test.";

include ("header.php");

?>

I tried this with and without the "global $page_title" and it wont work. Whats the simple thing I am doing wrong?

Tags:
Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 5 years 24 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Not sure what's wrong.

Not sure what's wrong. Variables are s'posed to be available to includes by default without needing to declare them as global. I don't think it's a PHP5 issue either because that's what I've got installed locally.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

I even uploaded this from my

I even uploaded this from my local server to my remote and it wont work on either. Strange... My files are below verbatim. Can someone test this out, maybe its my system or something?

header.php

<?php echo $page_title; ?>

index.php

<?php
$page_title = 'This is a test.';

include ('index.php');

?>

roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

Problem Solved

I use MAMP with for my locally and I restarted it and tried it and everything seems to be working now. Thanks Anyway