Welcome Guest, Not a member yet? Register   Sign In
Getting text data from another server
#1

[eluser]anndr0id[/eluser]
I have a website on another server I need to send a querystring to and it provides me with a number (not in XML, just a plain text #) and I'm having some problems with it. Hoping someone has had experience with this.

Code:
$user_email = "[email protected]"
$url = "http://www.server.com/home/main_servlet?COMMAND_CHECKOPTIN=" . $user_email;
$result = read_file($url);

In such case when viewing the $url in the browser it will be either "0" or "1", however I'm getting an empty return in the result for this query.

The only thing I'm thinking is its because the url is on a different server/site.. but they sent me this as their way to check e-mails, so there has to be some way to do it. The only other thing I was thinking is to take it out of PHP and send an AJAX request, but that seems like more work than its worth. Any suggestions??
#2

[eluser]steelaz[/eluser]
Do you have errors enabled (E_ALL)? Are you sure you want to use read_file()? It automatically outputs file contents to the page. Try file_get_contents() or better yet - CURL.
#3

[eluser]pickupman[/eluser]
It's actually easier to do in php, as AJAX probably won't allow a different domain for a request. Most browser prevent Cross Site Scripting for security purposes. You need to use php as your proxy, so you could AJAX to your page and get the string, and output it back. Using curl would be:
Code:
$curl = curl_init();
curl_set_opt($curl, CURLOPT_URL, "http://www.server.com/home/main_servlet?COMMAND_CHECKOPTIN=" . $user_email);

ob_start(); //start output buffer

curl_exec($curl); //get data
$string = ob_get_contents(); //save data

ob_end_clean(); //clean up
curl_close($curl); //clean up
#4

[eluser]anndr0id[/eluser]
Sweet! Curl worked perfectly, thanks for the suggestion Smile




Theme © iAndrew 2016 - Forum software by © MyBB