Contenu du cours
Module 1 — Discovering PHP
Understand what PHP is, set up a local environment and write your first script.
0/4
Module 3 — Functions, arrays and forms
Create functions, work with arrays and handle data coming from a form.
0/4
PHP for beginners

On a real website, the header and the footer are identical on every page. Rather than copying them everywhere, you put them in a separate file that you include.

The inclusion statements

  • include: inserts a file; if it is missing, it shows a warning but carries on.
  • require: the same, but it stops the script if the file is missing.
  • include_once / require_once: only include the file once.

A concrete example

  1. Create header.php with the site menu.
  2. At the top of every page: include « header.php »;.
  3. Change the menu once: every page is up to date.

For a vital file (the database connection, for instance), prefer require: it is better to stop the script than to carry on without it.

Key point: include and require prevent repetition. Use require for files you cannot do without.

Prix indicatifs, convertis depuis l'euro