0

I am very new to webscripting and technologies. So please pardon me if this is a very basic query. Further I have been researching this all day and I haven't been able to figure out why this is not working.

I am essentially trying to improve a website for my wife. The design dictates that we have a common header.php file that can be included into the various static pages that the website contains.

Now as a new requirement, they want to target a few static pages targeting different keywords, and for this the company wants to setup a different "Heading Message". So I want to dynamically pass a different "$page_heading" before I include my header.php.

My header.php has a bunch of HTML code with interspersed in between , so the following doesn't seem to be working:

    In <mypage.php>:
    ...
    <body>
        <div class="container">
            <?php 
                //global page_header;
                $page_header = 'A Wildlife Resort of South India';
                include('header.php'); 
            ?>
    ...
    In <header.php>:
    <header class="row-fluid">
        <div class="header-main">
                <a href="http://www.innthewild.com" class="pull-left"><img src="http://www.innthewild.com/img/itw-logo.png" alt="Inn The Wild" style="margin-top:8px;"/></a>
            <div class="pull-right" style="height: 20px;">
                <nav>
    ...
        <div class="heading pull-right">
            <?php
                    if(!isset($page_heading)) {
                        $page_heading = 'A Wilderness Retreat &mdash; Masinagudi Jungle Resort, India';
                }
                echo $page_heading;
            ?>
        </div>
    ...

The above seems like it should work straight up, but the variable seems to be losing its scope across a new instance. How do I make this work?

Here are the example pages: http://www.innthewild.com and http://innthewild.com/resorts-places-around-bangalore.php

2 Answers 2

3

You're calling it $page_header in mypage.php and $page_heading in header.php.

Change one or the the other so that the variable name matches across them

Sign up to request clarification or add additional context in comments.

2 Comments

Jeez!! That was embarrassing! I guess that is what happens when you are focused more on what else could be wrong and miss something as basic as this! Thanks very much DaveyBoy! I cant believe I wasted hours on this today! :-)
No prob. I've done it loads of times even in the same script without including any other files
0

u don't need to pass it

$some_var = "text";
include "some.php";

the script you just included can access the $some_var

1 Comment

Thanks very much for your response mc_fish. I already have that in the code above (see the example code above), and it doesn't work. See the variable $page_header and I always get 'A Wilderness Retreat &mdash; Masinagudi Jungle Resort, India' instead of 'A Wildlife Resort of South India'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.