You are here:  » Blank page when trying to parse url


Blank page when trying to parse url

Submitted by jmeier on Mon, 2008-09-01 11:19 in

I am having a problem getting results for one particular xml return data set from a url. If I try the url in the demo page it works fine, and I generate the code and use it. However when I acess the php page using the code, I just get a blank page. Every other url I have set up works fine.

This is the code:

<?php
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    print_r($record);
    // The following code will print out each field in your sample data:
    print $record["SUBS-INTERFACE-REPLY"];
    print $record["SUBS-INTERFACE-REPLY-VERSION"];
    print $record["STATUS"];
    print $record["MESSAGE"];
    print $record["LOGIN-REPLY"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST/ENTITLED-GAME-FEATURE"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST/ENTITLED-GAME-FEATURE/GAME-FEATURE-ID"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST/ENTITLED-GAME-FEATURE/STATUS"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST/ENTITLED-GAME-FEATURE/MESSAGE"];
    print $record["LOGIN-REPLY/ENTITLED-GAME-FEATURE-LIST/ENTITLED-GAME-FEATURE/ENTITLEMENT-EXPIRATION-DATE"];
    print $record["LOGIN-REPLY/LKEY"];
    print $record["LOGIN-REPLY/PROFILE-ID"];
    print $record["LOGIN-REPLY/ENTITLEMENT-EXPIRATION-DATE"];
  }
  MagicParser_parse("https://account.ea.com/subsxml/subsxml.jsp?locale=en&methodCall=login&screenname=[screenname]&password=[password]&game-feature-id=5148&date=73019310681","myRecordHandler");
?>

I have removed the screenname & password from the code above so it will not be able to be tested, however if I can send it via a pm or email I will gladly do that, just didn't want it available in the forum.

This is the result that is returned to the browser after accessing that url:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE subs-interface-reply SYSTEM "https://account.ea.com/subsxml/subs-interface.dtd">
<subs-interface-reply version="2.0">
   <status>0</status>
   <message>Success</message>
   <login-reply>
      <entitled-game-feature-list>
         <entitled-game-feature>
            <game-feature-id>5148</game-feature-id>
            <status>0</status>
            <message>Success</message>
            <entitlement-expiration-date>2008-09-01</entitlement-expiration-date>
         </entitled-game-feature>
      </entitled-game-feature-list>
      <lkey>SLPI0xDLWfn7RdDdCn4oOAAAKD0.</lkey>
      <profile-id>774119007</profile-id>
      <entitlement-expiration-date>2008-09-01</entitlement-expiration-date>
   </login-reply>
</subs-interface-reply>

I need to be able to read the message value and the lkey value. Thanks Jim

Submitted by support on Mon, 2008-09-01 11:38

Hello Jim,

Normally when opening URLs is a problem it is down to URL wrappers not being enabled on your server.

However, if other URLs are working fine, and this particular URL works fine on the demo script on
this server, then it may be a case of the remove server blocking access from particular user-agents.

To see if this is the case, the first thing to try would be to add the following code at the top of
your script:

  ini_set("user_agent", "Test");

Secondly, I notice that you are not using a format string value in your call to MagicParser_parse().

When a format string is not supplied, the parser has to read the entire document twice, so when
parsing remote URLs it is always worth providing a format string. In the case of the XML above,
the format string matching the $record keys that you are already using would be:

xml|SUBS-INTERFACE-REPLY/

...making your call to MagicParser_parse() as follows:

MagicParser_parse("https://account.ea.com/subsxml/subsxml.jsp?locale=en&methodCall=login&screenname=[screenname]&password=[password]&game-feature-id=5148&date=73019310681","myRecordHandler","xml|SUBS-INTERFACE-REPLY/");

If setting a user-agent doesn't work; the starting point for working out what's going on moving
forward would be the following test script, which doesn't involve Magic Parser:

<?php
  $url 
"https://account.ea.com/subsxml/subsxml.jsp?locale=en&methodCall=login&screenname=[screenname]&password=[password]&game-feature-id=5148&date=73019310681";
  
$fp fopen($url,"r");
  if (!
$fp)
  {
    print 
"Could not open URL";
  }
?>

However, I just noticed that this url is using https - so i'm wondering if the other URLs that
you are using which are working are normal http and not https. For PHP to fopen() https URLs
it must have been compiled with the Open SSL libraries built in.

To see if this is the case; run a phpinfo() on your server using the following code:

<?php
  phpinfo
();
?>

...and then near the top, beside the "Configure Command", look for:

--with-openssl

You should also find an "openssl" section lower down with further information about the
module. If it turns out that you don't have openssl compiled in, which will then almost
certainly be what the problem is, let me know and I'll point you in the direction of other
options, including using CURL if that is installed on your server (again, look for CURL in
your phpinfo), or perhaps shelling out to wget.

Cheers,
David.

Submitted by jmeier on Mon, 2008-09-01 12:35

Cheers David, it was openssl issue, moved over to my other hosted platform where it does work. now I have it all working correctly. This is a superb script. I have another beginner question. I am moving to php from a visual basic backround, and am looking for a clue on dealing with a specific element in a global array. I started my code based off of an example you supplied in the forum on using globals in an array. I get the array built fine and can iterate through all elements. What I am looking for is what do I call to read a specific element(which would be lkey) based on the code below.

<?php
  require("MagicParser.php");
$easoname = $_POST[easo_name];
$password = $_POST[easo_password];
$notifications = array();
  function myRecordHandler($record)
  {
  global $notifications;
  $easodata['Message'] = $record['MESSAGE'];
  $easodata['lkey'] = $record['LOGIN-REPLY/LKEY'];
  $notifications[] = $easodata;
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
  }
  MagicParser_parse("https://account.ea.com/subsxml/subsxml.jsp?locale=en&methodCall=login&screenname=$easoname&password=$password&game-feature-id=5148&date=73019310681","myRecordHandler");
   foreach($notifications as $notification)
  {
   //echo '<pre>'.print_r($notification,true).'<pre>';
  }
  ?>

Many many thanks David, your support on this excellent product is greatly appreciated.

Jim

Submitted by support on Mon, 2008-09-01 12:43

Hello Jim

When you use PHP's "append to the end of an array" notation, as in:

  $notifications[] = $easodata;

...the actual keys for each item are simply numeric and zero based.
So the first item added could be accessed through:

$notifications[0]

..itself an array; so then you could use the keys from the $easodata
array; for example:

$notifications[0]['Message']

If you want to know how many items are in the $notifications array,
you can use:

count($notifications)

...so the following snippets would have exactly the same result:

<?php
  
foreach($notifications as $notification)
  {
    print 
$notification['Message'];
    print 
"<br />";
  }
?>

and:

<?php
  
for($i=0;$i<=count($notifications);$i++)
  {
    print 
$notifications[$i]['Message'];
    print 
"<br />";
  }
?>

Hope this helps!
Cheers,
David.

Submitted by jmeier on Mon, 2008-09-01 13:46

Cheers, David, spot on. Hopefully I can muddle my way through the remainder without asking too many beginner questions. Great support!!!! Jim