Skip to main content

Adding Adsterra ads to a php-based website

Victoria V avatar
Written by Victoria V
Updated over 2 weeks ago

Intro

💡 PHP is a server-side language you can use to build your website. When someone opens your website, their browser sends a request to your server, where PHP code generates HTML and sends it back to the browser.

In practice, PHP websites are structured into multiple files to keep the code organized and reusable. A typical setup includes at least three basic files:

  • index.php – the main page, which assembles the different parts of your site.

  • header.php – contains the <head> section, navigation, and scripts that should load at the top.

  • footer.php – contains closing tags, footer content, and scripts that should load at the bottom.

The main page (index.php) usually includes the header and footer files using PHP’s include or require statements. This modular approach makes it easy to manage your site, update repeated elements, and insert Adsterra ads consistently across pages.


Ad placement recommendations

  • Popunder should always be placed before </head>.

  • Social Bar should always be placed before </body>.

  • Banner ads and Native ads can be placed flexibly:

    • Above or below the navigation in the header

    • Inside the article content

    • In a sidebar (<aside>)

Place no more than four banner ads per page to avoid banner blindness and thus hindered traffic performance. Always ensure ads are positioned thoughtfully to maintain user experience.


Testing Your PHP Website with Adsterra Ads

Before publishing, it’s important to verify that your ads appear correctly. You can test your site online using free hosting or locally using the PHP built-in server. Both methods allow you to preview your site and confirm ad functionality.

A. Online Test with Free Hosting (e.g., InfinityFree)

1. Register on a free hosting platform and create a website with a free domain.

2. Upload your three basic PHP files: index.php, header.php, footer.php into the hosting file manager:

3. Insert your Adsterra code snippets: place banners and native ads in the page body, Popunder before </head>, and Social Bar script before </body> :

4. Open your site using the provided domain in a browser to verify correct ad display.

Tip: For beginners, keeping all three files in the root folder is sufficient. For larger projects, you can organize files into subfolders.

B. Local Testing Using PHP Built-in Server

Local testing allows you to preview your site without uploading it online:

1. Create a project folder on your computer (e.g., PHP_site).

2. Create three PHP files: index.php, header.php, footer.php and include your Adsterra ad code:

3. Open Command Prompt and navigate to your project folder:

cd "C:\Users\User\Desktop\PHP_site"

4. Install PHP via Scoop (if not already installed):

scoop install php

5. Start the PHP built-in server:

php -S localhost:8000

6. Open your browser and go to http://localhost:8000 to see your site and ads in action.

Any changes to your files are reflected immediately when you refresh the page.


Placement and Styling Tips

Proper styling ensures that ads look natural and engage users effectively:

  • Use <aside> for sidebar placement, <header> for top banners, and <footer> for bottom scripts.

  • Center ads with CSS when needed:

    .ad-container {
    text-align: center;
    margin: auto;
    }
  • Maintain a maximum of four ads per page to prevent banner blindness.

  • Test multiple placements locally or online to determine which positions perform best.

💡 Note that we do not provide ads.txt files, as our advertisers do not require them.

If you still need it, you can contact us to request the required details and create the file on your own. We'll be glad to share the needed data with you!

Did this answer your question?