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

  • Home
  • SEARCH
  • 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 a class Page that creates an instance of DB , which is
I have a page base class that has no .aspx file and so I
I have class method that returns a list of employees that I can iterate
I have class with a member function that takes a default argument. struct Class
i am autpmating a web site that have different function page. i am making
I have a class named Page with a private property currently called _pageData which
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I'm trying to generate a CSS class that will help me define a page
I have an app with a login page that has three fields for three
I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is

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.