Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:06:30+00:00 2026-06-04T17:06:30+00:00

I have 2 includes on a page. Let’s say they’re the header and footer:

  • 0

I have 2 includes on a page. Let’s say they’re the header and footer:

<?php
include('header.php');
include('footer.php');

I need to use a variable from the footer in the header. Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:06:32+00:00Added an answer on June 4, 2026 at 5:06 pm

    Unless there’s a reason you can’t, the simple solution is to set the variable used in inc2 in inc1 instead.

    When a script is included outside of any function, the script executes in global scope, so anything it sets or defines that is scoped will have global scope. If a script is included within a local scope (such as in a function), the script executes in the same scope, so anything it defines is local. Note the included script can access variables local to a function.

    function foo($x) {
        $bar = 'bam';
        include 'script.php'; # script.php can access $x and $bar
    }
    

    However, global variables can be problematic. A better approach is to break down tasks into separate modules. Most modules are library scripts: they only define things (functions, classes) and don’t execute anything directly. The entry point (the top level script) doesn’t define anything; instead, it serves to connect everything and as a starting-off point for computation. Here’s a simple example with a database connection:

    <?php
    include_once('DB.php');
    include_once('header.php');
    include_once('footer.php');
    
    $db = DB::connect();
    header($db);
    footer($db);
    

    While technically $db is a global variable (note that this is merely sample code, rather than production code), it’s not to be accessed anywhere outside this script. Instead, it’s passed around according to the rules of capabilities (which was designed for security purposes, but the rules are actually just good OOP principles).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my index.php page and just afrer my header i want to include
I was wondering, If I have, let's say 6 javascripts includes on a page
I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
I have a live site that includes different php files depending on what page
I have a question on jQuery $(document).ready Let's say we have a HTML page
Let's say I have a project's urlconf which includes myapp 's urlconf: urlpatterns =
My dilemma is this: I have a PHP page with a form that includes
Let's say my page structure is : 1. one.html : includes -> a.js ,
I have a page that includes a GridView in it. That GridView is paged
I have a page that includes a dynamic js-script depending on the page I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.