Data From External Website

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
Rahvasaadik
Forum Newbie
Posts: 2
Joined: Sun Mar 15, 2009 10:24 am

Data From External Website

Post by Rahvasaadik »

Hi. I'm having an issue with getting an integer from an external website

Code: Select all

http://www.random.org/integers/?num=1&m ... in&rnd=new
Since that pages php script outputs only one thing into the source (the integer) i figured i could somehow make my php script goto that page and save everything in the source (or on the page for all that matters) into a predefined variable in a function.

Note that the page mentioned above generates a random number from atmospheric noise and I really need a total random number generator for my page. No pseudo-random stuff.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Data From External Website

Post by Benjamin »

What is your code?
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Data From External Website

Post by socket1 »

This code sets the variable, $Random, to whatever the page returns:

Code: Select all

<?php
$URL = "http://www.random.org/integers/?num=1&min=100000000&max=999999999&col=1&base=10&format=plain&rnd=new";
$handle = fopen($URL, 'r');
$Random = stream_get_contents($handle);
fclose($handle);
echo $Random;
?>
Rahvasaadik
Forum Newbie
Posts: 2
Joined: Sun Mar 15, 2009 10:24 am

Re: Data From External Website

Post by Rahvasaadik »

astions wrote:What is your code?
The problem was, that I didn't even have code, since I had no idea how to go about it.

Thank you socket1! It works like magic (makes future reference of the functions used in the script). :)
Post Reply