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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:03+00:00 2026-05-26T15:26:03+00:00

I have two scripts that I call with two PHP include() calls. The first

  • 0

I have two scripts that I call with two PHP include() calls. The first starts a session / sets cookies, the second loads one of two JavaScript scripts. To keep things valid, I’ve been using the two calls but I’d like to just combine them into one.

Current setup (simplified):

<? include "session.php" ?>
<!DOCTYPE HTML>
<html>
<head>
<? include "scripts.php" ?>
 ...

What I’d like:

<? include "session_and_scripts.php" ?>
<!DOCTYPE HTML>
<html>
<head>
...

But it’s invalid markup. Now if it really doesn’t matter, I’d like to do it this way. If there are serious repercussions, then I’m thinking of just echoing a DOCTYPE in the included PHP file, which I’d rather not do.

So which is better: echo the DOCTYPE, use include() twice, or use include() once and have invalid markup?

EDIT – The whole script (session and javascript) should ideally be fully implementable with one line of code (e.g. the one include())

  • 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-26T15:26:04+00:00Added an answer on May 26, 2026 at 3:26 pm

    Use ob_start at first to avoid problems with session_start

    <?php ob_start();?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <?php include "session_and_scripts.php"; ?>
    

    A way that uses only 1 1file and no additional instructions:

    <?php include "session_and_scripts.php" ?>
    <!-- more head-stuff-->
    </head>
    <body>
    <!--more content-->
    

    session_and_scripts.php should do the following:

    <?php
      //do the session stuff
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    
    <script type="text/javascript">
      //some javascript
    </script>
    

    (But I would’nt say it’s a good approach)

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

Sidebar

Related Questions

I have two PHP scripts, both using the same session by calling session_name('MySessID') .
I have two scripts that often need to be run with the same parameter:
I have two SQL scripts which get called within a loop that accept a
i have a script that calls a php file and gets an JSON object
I have a PHP script, that calls a python script by $call_python = python
I have two PHP scripts which both have an include_once('authentication.inc'); script near the top.
I have two session variables that I retrieve in a Javascript code. This is
I have a script that runs every two minutes for a Tweet-getter application. In
I have a script that generates two lines as output each time. I'm really
I have an MSBuild script that uses NUnit to run tests in two assemblies.

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.