Gen. partnerAlgotech

PHP Include - inserting a file into a page

As far as PHP is concerned, it will be automatically executed and understood as if it had always been at that location.

|
September 11, 2019

The include construct automatically inserts additional files/scripts into the current page.

As far as PHP is concerned, it will be automatically executed and understood as if it had always been at that location.

Example:

include 'news.html';

Practical use

  • Common menus and menus,
  • News, updates, news and the same content,
  • Header or footer, ...

Dynamic file loading

We often need to load files dynamically, for example based on a variable.

For example:

$clanek = 'neco';
include $clanek . '.html';

Or we can dynamically load articles into the page:

include 'articles/' . $_GET['page'] . '.html';

Calling a URL with the page parameter will automatically insert the article, for example: https://example.com/?page=novinky.

Loading comments...

Stay in the loop

Subscribe to our newsletter and get the latest cybersecurity news delivered straight to your inbox.

Your data is safe. You can unsubscribe from the newsletter at any time.