p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP How-To (http://p2p.wrox.com/forumdisplay.php?f=98)
-   -   how to set php variable value from external site (http://p2p.wrox.com/showthread.php?t=98618)

redfox February 14th, 2016 12:48 AM

how to set php variable value from external site
 
I am a PHP novice and would appreciate some advice on how to achieve the following.

At hypothetical location "no_name_site.com/.count", the file .count contains a numeric string only, for example, 123. The content constantly increments. I want to display the current count at my own web page.

Something like this:


<html>
<?php
$foreign_count = {the current value stored at "no_name_site.com/.count"}
?>
<body>
<center>
<h1>Foreign Site Count</h1>
<p>count = <?php echo $foreign_count; ?></p>
</center>
</body>
</html>

Is this possible in PHP ?

redfox February 14th, 2016 05:32 PM

solution
 
I found the answer on StackOverflow by searching for a slightly different title, "how to set php variable value from external domain".

<?php
$foreign_count = file_get_contents('http://no_name_site.com/.count');
?>


All times are GMT -4. The time now is 09:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.