<div id="hedar_main">
            <div id="hedar1">
               <?php include('menu.php')?>            
            </div><!--end of header1 -->
        </div><!--end of header-main -->
     </div><!--end of header -->

<div class="rightdiv">
               <?php include('local_auth.php')?> 

               <?php include('news.php')?>

               <div class="midal_right">
                <center><div class="divimg"><img src="images/home_img1.jpg" /></div></center>
                <center><div class="divimg"><img src="images/home_img2.jpg" /></div></center>
               </div><!--end of midal_right -->  
              </div><!--end of rightdiv -->
<div id="futter">
    <div id="futter_main">
        <div id="futter1">
         <?php include('footer.php'); ?>
      </div>
    </div>
</div>               

Here I included 4php file So my question is that is this proper way of coding please guide me ...
Thank you in advance..!

Dani AI

Generated

Including several PHP files from one page is perfectly normal and the approach in the original post will work. Several replies already covered that basic point — and were right — but a few practical details make multi-file layouts more robust, maintainable, and secure (points raised by , , and ).

Use the right include type for the job: require vs include and their _once variants behave differently on failure and prevent duplicate declarations. Essential bootstrap/config/class files belong behind require/require_once; optional templates or widgets can use include. Keep in mind the included file runs in the caller’s scope (variables available before an include are visible inside it, and an include inside a function executes in that function's scope). An include returns the included file’s return value (or 1) when successful.

Avoid path problems and duplication by using absolute paths (for example, __DIR__ or an application root constant) and centralizing shared assets in an includes/ directory. For optional files use a simple existence check before including to avoid warnings. For class loading, prefer an autoloader (PSR-4 / Composer or spl_autoload_register) rather than manually including every class file.

Security and maintenance notes: never include filenames derived directly from user input (whitelist if needed); disable allow_url_include; store non-public logic outside the web root or ensure included PHP files cannot be served as plain text; set sensible file permissions and error-reporting levels (development vs production). Log failed includes so missing files are noticed during testing.

Example pattern (reliable paths, single-inclusion for core files):

<?php
require_once __DIR__ . '/inc/config.php';
require_once __DIR__ . '/inc/bootstrap.php';

if (file_exists(__DIR__ . '/inc/optional-widget.php')) {
    include __DIR__ . '/inc/optional-widget.php';
}

This combines the practical guidance discussed in the thread with safer defaults and clearer behavior when an included file is missing or redeclared.

Recommended Answers

All 17 Replies

Yes this is all fine

Yes, you can include multiple files in PHP Code.

Having multiple files is possible :)

yes lol why not

Member Avatar for Member #120589

This is turning into a 'me too' thread. Can we all agree that you can, and wait for the OP to return? Oh darn, I just did it too. :(

commented: Good one :) +5

no problem but best for use

 include_onc() 

function

@rajeev,

That should be -

include_once()

:) Oh, almost forgot, me too. ;)

better still require_once()

Member Avatar for Member #120589

the various includes and requires have different uses, so choose the right one for the job. One isn't necessarily better than another in all cases.

you right in some cases

Thank you to all....!!

Member Avatar for Member #120589

OK, are we solved?

You may mark this solved now... hopefully this has answered your question.

@MICHAEL Sorry to say but I don't know how can I marked it solved??
Please help me...
Thank you.

Yes, you can add multiple includes. But, best you can add include_once instead of include.

Member Avatar for Member #120589

@MICHAEL Sorry to say but I don't know how can I marked it solved??

There's a link button at the bottom of the screen to mark the thread solved.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.