0

I am having a problem using the curl lib with php. What I want to accomplish is to make multiple request pulling xml returned from two different url's that are called with curl. Here is the code:

$BROWSER="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 YFF3 Firefox/3.0.1";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.wowarmory.com/character-sheet.xml?r=Crushridge&n=Thief");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

curl_setopt($ch, CURLOPT_USERAGENT, $BROWSER);


$result20 = curl_exec($ch);

curl_close ($ch);

/**

I extract the values out of the xml here

**/

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.wowarmory.com/character-sheet.xml?r=Ursin&n=Kiona");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

curl_setopt($ch, CURLOPT_USERAGENT, $BROWSER);


$result20 = curl_exec($ch);

curl_close ($ch);

/**

I extract the values out of the xml here
**/

When I make the first call I can extract the values, but when I make the second call I can extract the values but they are the values of the first call.

1
  • This code snippet seems to be all right, maybe you're making a mistake somewhere else? Commented Sep 2, 2009 at 2:28

2 Answers 2

1

This code works fine, it returns two different pages. Is it possible your extraction takes place after both calls, and not one after the other as you specify? If so, then they would match as you use $result20 twice.

If you load those URLs directly in your browser, do they return different pages (they do for me).

Sign up to request clarification or add additional context in comments.

Comments

0

The code works fine for me, too. As Justin suggested, you're probably overwriting your extracted data.

May I suggest less-redundant code? For example:

$urls = array('http://www.wowarmory.com/character-sheet.xml?r=Crushridge&n=Thief',
              'http://www.wowarmory.com/character-sheet.xml?r=Ursin&n=Kiona');
$browser = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 YFF3 Firefox/3.0.1';

$ch  = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $browser);

foreach ($urls as $url) {
    curl_setopt($ch, CURLOPT_URL, $url);
    $result20 = curl_exec($ch);
    // Extract the values out of the xml here (to separate variables).
}
curl_close($ch);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.