Accessing another URL for information

Posted on 2012-09-07
Medium Priority
Last Modified: 2012-09-24
I've got a situation where I'm having to retrieve data from another server.

The page my user will access has on it a statement that says, "Look how we've helped our members thus far:" After the ":," there will be a number that represents the number of pounds their membership has lost that year.

That number will be computed using a database and script sitting on another server. Obviously it would be a slam dunk if I could put everything on the server my user is accessing, but that isn't the case, at least right now.

So, is there a way I could use a "GET" dynamic to retrieve the number I need?

Question by:brucegust
LVL 58

Expert Comment

ID: 38376331
If that is all that is on the page then just do an ajax call and strip (split) everything before ":,"
Plain ole js or jquery if you can.
LVL 32

Assisted Solution

DrDamnit earned 1000 total points
ID: 38376385
On your server that has the data, write a script that exports the information as XML and displays it as text. http://www.serverwithdata.com/hiddenscript.php

On the server that is displaying the data, use cURL to grabt that XML file.

Parse the XML,

Display the data.


Author Comment

ID: 38376414
Doctor, I'm digging your suggestion and while I'm familiar with cURL as far as some of the ecommerce stuff I've done, I would welcome an example if you could provide one as well as an XML example of how that would work with what I'm trying to do.

Or, if there's an online tutorial, that would be great too.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 60

Accepted Solution

Julian Hansen earned 1000 total points
ID: 38376591
Here is some code I used in a site a while back.

Pass in an xml packet with parameters - get an xml string back
The XML (Sample with function type and value) - service returns value * 5.

Open in new window

The Service
$data = file_get_contents('php://input');
$result = 0;

if (!empty($data)) {
	$xml = new SimpleXMLElement($data);
	$result = $xml->value * 5;
echo "<response>

Open in new window

The Client
function getXML($xml, $url, $timeout=30, $encode=true)
  $curl = curl_init($url);
  curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
  curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_HEADER, 0);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
  curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT    5.0'); 
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  $http = curl_exec($curl); 
  $info = curl_getinfo($curl);

  $xml = new SimpleXMLElement(html_entity_decode($http));
  return $xml;

$xml = <<<XML

$xml = getXml($xml, 'http://server/getxml.php');
echo $xml->result;

Open in new window

LVL 111

Expert Comment

by:Ray Paseur
ID: 38376742
Please post the URL of the foreign server.  I expect I can give you a tested and working code sample that will return the number.  Thanks, ~Ray
LVL 32

Expert Comment

ID: 38377112
julianH has a great example already.

If you tell us what the data is / what it looks like, we'll be able to help you with even more.

Author Comment

ID: 38429797
Hey, guys!

Thanks for your time, one and all.

I was able to work around the problem in a way where I just displayed the data on a screen that was coming from the URL where the data was being stored. I'm award points to those who logged in and thank you so much!

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question