Here is my include file data.php:
<?php
$name = "Noob";
?>
This file is in my local server as well as my online server.
And here is my code:
<?php
//include("./data.php");
//include("http://localhost/webdev/test/php/remote_include/data.php");
//include("http://example.com/data.php");
echo "Hello $name.";
?>
Now, in the 3 commented lines, the first line works, and Hello Noob. is printed. But the next 2 lines do not work and Hello . is printed.
Why?
My guess is, when I include using http, the PHP file actually gets run and thus the main script (which calls the include) does not know which variables are set and can only see what PHP prints. Is that correct? If that's the case, say my data.php file (which is in my online server) has top secret database information of my awesome (noob) blog site. So someone cannot just include() my file (using http or any other possible method) and get the database info by echoing the variables?
Sorry if it's too noob of a question and has been asked before.
$nameis not being set in the latter 2 cases.