t_mo_t Posted November 18, 2011 Share Posted November 18, 2011 Hey guys, I m not an expert in PHP but i want to learn php now. So the question is, So i have 2 machines that I want to communicate; let's say 192.168.1.5 and 192.168.1.7 And then, there is a php called test_main.php in 192.168.1.5, then test.php in 192.168.1.7 My goal is to call test.php and then capture the echo result... is it possible? kinda like: in test_main.php <?php echo file_get_contents("http://192.168.1.7/test.php?test=123123"); ?> in test.php <?php echo "HELLO WORLD!"; ?> so the output when i call test_main.php is "HELLO WORLD!" Thanks guys! Appreciate it P.S. Maybe the function that I m using is incorrect? Please let me know of another function to use? Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/ Share on other sites More sharing options...
nethnet Posted November 18, 2011 Share Posted November 18, 2011 There are a few different ways to achieve this, each with their own pros and cons depending on what you want to do with the file. If you are just looking to grab the OUTPUT of the PHP script, I would recommend using fopen() to open the file, and then readfile() to load the output of the file into a variable. This, also, assumed that you have allow_url_fopen enabled on your system. Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289200 Share on other sites More sharing options...
t_mo_t Posted November 18, 2011 Author Share Posted November 18, 2011 hey, Thanks for the reply... but if it's not under the same ipaddress, it's ok to use open file? Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289205 Share on other sites More sharing options...
nethnet Posted November 18, 2011 Share Posted November 18, 2011 Yes, you can use file handling functions as long as allow_url_fopen is enabled on your system. Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289218 Share on other sites More sharing options...
exarhis Posted November 18, 2011 Share Posted November 18, 2011 You can even f_open google ex. It has to be accessible by the http or https Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289221 Share on other sites More sharing options...
t_mo_t Posted November 18, 2011 Author Share Posted November 18, 2011 hmm hehe guys, found out i can also use curl_exec too! anyway, learned so much from this..thanks alot for your help!! Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289230 Share on other sites More sharing options...
exarhis Posted November 18, 2011 Share Posted November 18, 2011 But is far better to make them communicate through database ! Quote Link to comment https://forums.phpfreaks.com/topic/251354-capturing-echo-from-another-page-help/#findComment-1289257 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.