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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:10:49+00:00 2026-06-03T09:10:49+00:00

If I include or require one PHP script from another, e.g. include ‘header.php’; ,

  • 0

If I include or require one PHP script from another, e.g. include 'header.php';, should the included PHP script also use the opening <?php and closing ?> tags, or not?

Whether the tags are present or not, the script loads correctly. But I’m unsure which is the correct procedure. My concerns are: (1) by using the tags again the PHP engine might start up twice and waste resources, (2) by not using the tags, this may be incorrect and could break in future, also other people might be able to see the PHP code (if it were inside of the public directory).

EDIT

People are misunderstanding this question. Here is some background: when you include or require a file it is dropped into place in the parent file dynamically and they are parsed as one script. The included script is not executed/interpreted separately, it just continues. This is why the tags are NOT needed. That is not my question. My question is whether it is better (recommended by PHP?) to use the PHP tags in this case, or to exclude them entirely from the included scripts.

  • 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-03T09:10:50+00:00Added an answer on June 3, 2026 at 9:10 am

    If your include/require file is PHP, open it with the php tag <?php. Generally, you don’t close the php tag if there is nothing after it as it is optional.

    The closing tag of a PHP block at the end of a file is optional, and
    in some cases omitting it is helpful when using include or require, so
    unwanted whitespace will not occur at the end of files
    , and you will
    still be able to add headers to the response later. It is also handy
    if you use output buffering, and would not like to see added unwanted
    whitespace at the end of the parts generated by the included files.

    http://php.net/manual/en/language.basic-syntax.instruction-separation.php

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

Sidebar

Related Questions

In PHP: When should I use require vs. include ? When should I use
One of the ncie things about PHP is that if you do an include/require
In my live site I have php include() and require() that have full path
I'm using require_once() in header.php to include the FirePHP library. In the page.php I'm
Is there any way to include php file using require and calling a php
What is better practice for script performance tuning? This one? require_once(db.php); if (!is_cached()) {
I have a PHP script like this: <?php include 'authorization_script.php'; foreach ($_POST as $key
I'm trying to add jQuery using Greasemonkey's @require / @include method, but it doesn't
How would I go about checking if and include or a require has an
Is it more efficient to use PHP's include_once or require_once instead of using a

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.