You are here:  » Accessing password protected XML feed with interactive user name and password session?

Support Forum



Accessing password protected XML feed with interactive user name and password session?

Submitted by mangopudding on Mon, 2009-12-07 06:40 in

Hi there.

I've been using MagicParser for the last few hours and I just LOVE IT. It's made my development efforts so much easier (since I'm not a programmer!). :)

I've created a webpage where I want the user will need to enter in their user name and password to access a secured XML feed. I was wondering if this is the best way to do it - or is there a more elegant way?

<?php
  require("MagicParser.php");
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="Connect To XML API"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'You have cancelled your authorization session.';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
  $filename = "https://{$_SERVER['PHP_AUTH_USER']}:{$_SERVER['PHP_AUTH_PW']}@password_protected_website_where_xml_is_located";
  function myRecordHandler($record)
  {
    print_r($record);
  }
  MagicParser_parse($filename,"myRecordHandler");
}
?>

Submitted by support on Mon, 2009-12-07 08:53

Hello,

That looks fine - perfectly minimal, and doesn't rely on cookies or any other form of potentially by-passable authentication since the user must know the username / password of the remote site. Looks good to me!

Cheers,
David.

Submitted by mangopudding on Mon, 2009-12-07 16:57

Thanks David!