Reputation: 77
I have file at some server... file is www.iamtushar.com/file/index.php
<?PHP
$var=2;
?>
Now i want to include this file and use the value of the variable $var on some other server..
Suppose the other script is www.howtodothis.com/index.php and i want to use $var of the above file here....
<?php
include('www.iamtushar.com/file/index.php');
echo $var;
?>
but it does not work, however it works if the file is on the same server and same browser..
please help...
Upvotes: 0
Views: 878
Reputation: 1954
Instead of using the include
keyword, use the require
keyword. Simply replace like this
require('www.iamtushar.com/file/index.php');
echo $var;
Even better, if you wish to save processing time, just use the require_once
keyword as so. This way, you ensure that in 1 page load, you only load this PHP file once. Also, it prevents confusion between variables of the same name in different files. You can do so using
require_once('www.iamtushar.com/file/index.php');
echo $var;
Upvotes: 0
Reputation: 1635
Aside from security concern, If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper) :
include 'http://www.iamtushar.com/file/index.php';
Upvotes: 0
Reputation: 26511
It does not work since PHP can only output yout $var
to client. Making this, I believe, is possible if you output content of your index.php
file to client and then your other index.php
file gets it and than compiles it on the fly. However it's very bad idea for security/speed reasons.
Your best bet is to output $var
to browser. Than your other script will take that 2
and place it in your other $var
.
Upvotes: 1