evaluate php script and pass php variable to aother php

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

Post Reply
eugene2006
Forum Newbie
Posts: 19
Joined: Fri Oct 28, 2005 6:09 pm

evaluate php script and pass php variable to aother php

Post by eugene2006 »

hello!

lets say php script is here http://abc.com/a.php
this a.php works with inner mysql database "localhost" etc.
after all it returns answer like

echo "<b>".$country."</b>";
which is lets say outputs html <b>UK</b>

when i go to http://abc.com/a.php
it is fine, it shows me what i want it shows value of $country = <b>UK</b>;

but the problem is how do i get this value of $country from another location
lets say URL is like http://xyz.com/b.php ?

include did not work i did something wrong there...

how to evaluate things in php and then pass to another php script?

.............

in javascript there is no problem, all you have to do is do like this
<script src="http://abc.com/a.php"> </script>
and in javascript working space would be <b>UK</b>, which ofcourse leads to an error, but it is not a point
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if the file is outside the current domain, you will (very very ver likely) not be able to get any of its internal variables.
eugene2006
Forum Newbie
Posts: 19
Joined: Fri Oct 28, 2005 6:09 pm

Post by eugene2006 »

fopen ok?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

eugene2006 wrote:fopen ok?
Pardon?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

If the script is on the same server and you just want the output value, make a function to return the value and just use it in both places...

if it is on another server just do it like this:

Code: Select all

$h= fopen('http://example.com/a.php', 'r');
$variable = fread($h);
fclose($h);
echo 'The country is: '.$variable;
Post Reply