Embed Ads or File In Your PHP Web App Using Include or Require function

Am writing this post as a result of the frequent message have been receiving from some webmaster new to PHP.
This post is aim at explaining how to include Ads or file to a PHP web script/app using include or require function.

Follow the few step below to achieve this.

Note: Include and require are identical, except upon failure.
require will produce a fatal error and stop the script while include will only produce a warning (E_WARNING) and the script will continue So, if you want the execution to go on and show users the output, even if the include file is missing, use include. Otherwise, in case of FrameWork, CMS or a complex PHP application coding, always use require to include a key file to the flow of execution. This will help avoid compromising your application’s security and integrity, just in- case one key file is accidentally missing.
You may change all include in the sample code below to require if that’s the option you choose to go with.

  1. Create a file with any name of your choice, for this example, let’s name it ads.php
  2. Open the created file(ads.php) and insert the Ads PHP code and save it.
  3. To include the advert in your desire location, use the below code snippet

    <?php include ‘ads.php’; ?>
  4. If maybe the created file(ads.php) was saved in a path folder called “appname” with path /public_html/appname/, then the php code will be

    <?php include ‘/public_html/appname/ads.php’; ?>

    OR

    Rather than include the full file path that begins with “public_html” (popularly the name for the root folder of most shared webhosting server), u may change /public_html/appname/ in the code above to ../appname/.
    The “..” denote the root folder.

  5. If for example, the ads.php was saved in the a folder/directory same with the file you want to edit and include the ADS, then no need including the file path, just a simple include call to ads.php will do, i.e

    <?php include ‘ads.php’; ?>
Don’t miss out!
Subscribe to My Newsletter
Invalid email address