Search code examples
phpfunctionincludeabsolute-pathdocument-root

require_once() function unable to include functions()


index.php

<?php
require_once('fr.php');
header('Location:'.abspath().directory());
?>

fr.php

<?php
require_once('functions.php');
?>

functions.php

function abspath()
{
return $_SERVER['DOCUMENT_ROOT'];
}

Now when i go to index.php, it gives me this error:-

Fatal error: Call to undefined function abspath() in C:\xampp\htdocs\index.php on line 3

Solution

  • Hey all my commenting people were right... i don't know why it happened but when i restarted my xampp it worked fine for me :)

    So this is 100% correct

    index.php

    <?php
    require_once('fr.php');
    header('Location:'.abspath().directory());
    ?>
    

    fr.php

    <?php
    require_once('functions.php');
    ?>
    

    functions.php

    function abspath()
    {
    return $_SERVER['DOCUMENT_ROOT'];
    }