misdirection misdirection - 3 months ago 9
PHP Question

put variable inside php include path

I'm trying to access a file inside a folder, but the problem is the variable is not working.

What I want is once the user visit the site the variable $site and path should be 'domain.com/inc.index.php'

here is my code

$site = $_SERVER['SERVER_NAME'];

include '$site/inc.index.php';


Error

include($site/inc.index.php): failed to open stream: No such file or directory


I found the same problem but its not working for me.

https://teamtreehouse.com/community/how-do-i-put-a-variable-inside-include-path

Answer

You should use the double quote and not a single for that:

include "$site/inc.index.php";

The single quote will not parse the values of the variables in your string, while the double quote will.

Comments