misdirection misdirection - 2 months ago 5x
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';


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.



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.