Search code examples
phpserver-side-includes

Passing variable to an include


index.php

<?php
    $title = "This is the page title";
    require_once '/includes/header.php';
?>

header.php

<head>
    <title><?= $title ?></title>
</head>

Output

enter image description here


Solution

  • I think short tags may not be enabled. Try:

    <title><?php echo $title ?></title>
    

    instead