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 392971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:12:42+00:00 2026-05-12T16:12:42+00:00

I have a class Page() that I can use to print the (layout) header

  • 0

I have a class Page() that I can use to print the (layout) header with.

With the function loadHeader($title) I want to be able to print it on all my pages. The actual code for the header is stored in header.inc.php.

Now before the header I also want certain variables (like one which maintains a database connection) to be passed along with it, so that I can pick it up on all my pages and work with it.

The class looks a bit like this (thined out to prevent a mess):

class Page{
    //All vars here
    function __construct(){
        //constructor code
    }
    function loadHeader(){
        $header = file_get_contents("header.inc.php");
        //Some editing of the parsed $header here

        //Here I want certain variables to be passed along 
        return $header;
    }
}

The exact code I want to get passed along with the function loadHeader() is:

session_start();
include("db.class.php"); //File which contains the db_class
$db = new db_class;
$db->connect();

Tried doing this with eval() and heredoc within the loadHeader() function but I can’t seem to get this working. I’m desperate!

Finally to give you an example on how I want my pages to work:

<?php
    include("page.class.php");
    $page = new page("Friends");
    $page->loadHeader();
?>
Website content with database manipulation
  • 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-05-12T16:12:43+00:00Added an answer on May 12, 2026 at 4:12 pm

    Why don’t you just put that code in the Page constructor?

    Or make a generic singleton class which will hold your global data, configuration settings, etc?

    Or simply add an auto_prepend with that configuration, so that it automatically is included in any page, and you can completely forget about it?

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

Sidebar

Related Questions

I have jquery with class= modal i want to call that class when page
I have an intermediary class extending System.Web.UI.Page for all of my pages that require
I have a Test Class, that test the access of all page with different
i have an application that loads the page content. I use the WebClient class.
I have a page that is setup like this public partial class _Default :
I have a class that inherits from Page, called APage. public abstract class APage:
I have an Employee class object that I am calling from my Login.aspx page's
I have to open a page from class extended from javax.swing.AbstractAction class... Is that
I currently have a PrintingWebService that I call from an AJAX page with all
In C#, I have a class set up like so: class Page { public

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.