PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
noorodeen
Forum Newbie
Posts: 4 Joined: Sun Jan 07, 2007 2:57 pm
Post
by noorodeen » Sun Jan 07, 2007 3:11 pm
Hello All,
I've searched quite a bit to try to find answer to this but to no avail. I am hoping you can help me out here.
I am including a remote script in my code and I want the remote script to return a value. How can I do that?
Here's the snippet of code:
Code: Select all
$var = include 'http://www.example.com/file.php?var1=$var1&var2=$var2';
Now, I have tried to get global variables in file.php, I tried using return $var....
Any ideas on how I can this going?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Sun Jan 07, 2007 3:51 pm
When you include the page as a URL, it will be processed by php and apache and you will "include" the
resulting output . So unless the script
outputs something like:
you won't get the result you're looking for.
Does that make sense?
Last edited by
Kieran Huggins on Sun Jan 07, 2007 3:59 pm, edited 1 time in total.
noorodeen
Forum Newbie
Posts: 4 Joined: Sun Jan 07, 2007 2:57 pm
Post
by noorodeen » Sun Jan 07, 2007 3:58 pm
ok. So in other words, if I want to return a value, a number and assign it somewhere in the calling script, how can I do that?
I think I understand what you are saying. You're saying I need to do teh following in my remote .php file
that's what you are saying right?
Thanks
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Sun Jan 07, 2007 4:01 pm
sorry - had a typo in my previous post (now fixed):
Do something like this:
noorodeen
Forum Newbie
Posts: 4 Joined: Sun Jan 07, 2007 2:57 pm
Post
by noorodeen » Sun Jan 07, 2007 4:02 pm
Hey, you're awesome. It worked. I've been trying different things all day.....
Thanks a lot.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 07, 2007 5:10 pm
Take care when requesting a file for inclusion from a remote location. It is often a security hole waiting to be exploited. I would suggest using
file_get_contents() and assigning the variable yourself.
Hyper
Forum Newbie
Posts: 2 Joined: Mon Jan 15, 2007 12:10 pm
Post
by Hyper » Mon Jan 15, 2007 1:11 pm
Kieran's way results in that line being echoed, not parsed in any way. I don't know why so I used some other way.
remote script which is exporting some useful (not in this case ) data:
Code: Select all
$fruits = array( 'apple', 'banana', );
var_export($fruits); // prints parsable contents of the variable
above $fruits elements can now be recreated (redefined) in other script in following way:
Code: Select all
$imported = file_get_contents("url_here"); // get contents of remote file
eval('$fruits = '.$imported.';'); // $fruits will hold the imported data
print_r($fruits);