PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Table of Contents

PHP Includes

PHP Includes allow you to include one PHP file or HTML file inside of another. So let's make a file in which we can store all of our functions. Let's call that file functions,php. Then let's put a greeting function in there.

<?php

    function greeting(){
        return 'Welcome to Includes';
    }

?>

Now, if we want to use this function everywhere, we just have to add the functions.php file in all the other files using a function called include like this:

<?php
    include "functions.php";
?>
<!DOCTYPE html>
<html>
<head>
    <title>My First PHP App</titile>
</head>
<body>
   
    <h1>Home Page</h1>

    <p><?php echo greeting(); ?></p>

</body>
</html>

The include function has to be at the top of our file, just like the session_start function.