Authenicate a connection to remote server.
| From: | Len Coonan | Date: | Tue, 16 Oct 2001 12:29:41 +0000 |
| Subject: | Authenicate a connection to remote server. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71201@lists.php.net to get a copy of this message | ||
Hi, I am running a site and have got access to a news provider that will allow me to display news
headlines on my site that link to the articles on their site. My problem is that they use HTTP
Authentication to enable me to access their files automatically. I know I can use fopen to open
files remotely, but how do I authenicate myself first.
They have provided me with a perl script as follows.
In order to automate the process of authenticating and downloading, one
needs to have some skills in perl scripting. One could very easily
write a small perl script that uses the LWP perl module for user
authentication. As an example piece of code:
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request 'GET', 'http://news.news.com.au/finance.html';
$req->authorization_basic('userid', 'password');
my $result = $ua->request($req)->as_string;
This allows one to embed the username and password assigned to them into
a script that will complete the authentication process for them. From
here one simply needs to parse the returned file and extract the links
that are given. These links can be used in whichever way seen fit.
My question is, can I do this with PHP, and if so, could someone please point me in the right
direction.
thanks
len.