hex4
hex4

Reputation: 695

Include through HTTP

I have a file on another server which I can trust since it's my own code that in it there is an array with some settings.

When I include it using the include_once and print_r the variable in it, I am getting an undefined variable.

I also tried to return the variable from the file I am including and assign it to a variable in the script like this:

$var = include($url);

where $url has:

$array = array(1,2,3); return $array;

when I print_r($var) I only get 1.

Upvotes: 0

Views: 274

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 157989

remote host:

echo serialize($array);

local host:

$array = unserialize(file_get_contents($url));

Upvotes: 1

Joey Ciechanowicz
Joey Ciechanowicz

Reputation: 3663

It's because the other server will parse the file and return the RESULT, not the actual code. you need to get the actual contents of the file, which will only be possible if you disable php on the other server or ftp to it. I would recommend copying the file over to the server you're working on, safer an easier

The file you are trying to get will come back the same as if you went there in your web browser because the remote web server will parse the contents of the file though the php engine.

Upvotes: 2

Related Questions