Reading data from an HTTPS Link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Reading data from an HTTPS Link

Post by andycain »

Hi guys,

I have access to a secure server that contains schedules and lists amongst other things and I want to display this information on my own sites secure section via a PHP script.

The HTTPS url requires you to login. Can I pass the login information to the HTTPS server and download the content using the php script without having the user to type in the username / password combination?

This is the script I have so far. My server doesn't support cURL so I need a work around.

Code: Select all

 
<?php
 
$url = "https://secureserver.co.uk";
 
$user = "username";
$pass = "password";
 
$data = fopen ($url,r);
 
$calendar = fread ($data);
 
echo $calendar;
 
?>
 
Now clearly whenever I run this script I get a 401 Unauthroised error. This is because I don't know how to pass the credentials to the server.

I've been reading about secure sockets, digest authentication etc and it's not really making much sense!!

EDIT: I asked my webhost to install cURL. Their response in a nutshell: 'no'

Any ideas would be great!

Andy
Last edited by Benjamin on Tue May 19, 2009 8:27 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Reading data from an HTTPS Link

Post by Christopher »

There is a class called Snoopy that does much of what cURL does.
(#10850)
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

Okay.

I downloaded that from sourceforge and used this script....

Code: Select all

 
<?php
 
include ("Snoopy.class.php");
 
$snoopy = new Snoopy;
 
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$snoopy->referer = "http://www.83sqn.co.uk/secure pages/secureindex.htm";
$snoopy->rawheaders["Pragma"] = "no-cache";
 
//passwords
 
$snoopy->user = "Username";
$snoopy->pass = "Password";
 
 
$data = $snoopy->fetch("https://www.mysecureserver.co.uk");
 
 
echo $snoopy->results;
 
?>
 
 
This sends back a blank page. No error, no content. Nothing.

It works fine when I use an HTTP link.

Any thoughts?
Last edited by Benjamin on Wed May 20, 2009 8:07 am, edited 1 time in total.
Reason: Changed code type from text to php.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Reading data from an HTTPS Link

Post by crazycoders »

Does the snoppy class uses it's own internal mechanism to access external pages? If so, it's maybe not designed to use HTTPS.i
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

I'm not sure. I've only heard about it today...

I've been googling this and not found many answers but some people have been saying it links with the cURL library which isn't installed on my server...hence why I'm using Snoopy.

Surley I would get an error back if this were the case?

Is there no way to pass HTTPS login credentials using fopen / fread ?
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

Anybody?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Reading data from an HTTPS Link

Post by Christopher »

Did you look in the Snoopy source? As I recall it is pretty easy to understand.
(#10850)
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

Yer I've looked in the snoopy source and it definatly needs cURL installed to work which puts me back to square one.

How do I access an HTTPS link using PHP without using cURL?

There must be a way surely?!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Reading data from an HTTPS Link

Post by Christopher »

First, Snoopy need the command line version of cURL installed -- not the extension. So you may try that. Otherwise you make need to make the call in a frame and get the frame contents using Javascript.
(#10850)
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

How would I use Javascript to access an HTTPS link?

Is it possible?

If so I'll look up how to do it myself unless anybody wants to let me be lazy and tell me how :D
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Reading data from an HTTPS Link

Post by andycain »

Any ideas anybody? I don't mean to pester but this problem is really bugging me!
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: Reading data from an HTTPS Link

Post by kaisellgren »

You could just use fsockopen(), although it requires plenty of coding from your side. You could try to look at PEAR.
andycas
Forum Newbie
Posts: 1
Joined: Thu May 28, 2009 3:32 am

Re: Reading data from an HTTPS Link

Post by andycas »

I need the same thing with snoopy. Im trying to fetch some info from xbox.com. So how would i log in with snoopy to this: https://login.live.com/login.srf?
Could someone post example?
Post Reply