Page 1 of 1

Getting source from protected site

Posted: Sun Dec 03, 2006 8:29 am
by alon
Hello,

I’m trying to get a page source from a site.
I’m using a simple script :

Code: Select all

<?php
$handle = fopen("http://example.com ", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
  }
print ($contents);

fclose($handle);
?>

It works for the usual cases.

The problem I have is that I want to retrieve the information from a page that is on a site that I must enter my login credential first. Then I get only part of the page and not all the information as if I didn’t login.
I’m not trying to hack the page- it’s my information in it, but I want it copied to another place.

I tried adding the username and password to the fopen call :
fopen("http://username:password@example.com ", "rb");

But it didn’t work.

Any help would be appreciated.

Thanks,
Alon

Posted: Sun Dec 03, 2006 8:35 am
by feyd
What kind of login is required to get in to these pages? Is it Basic HTTP Authentication?

Posted: Sun Dec 03, 2006 8:45 am
by alon
I don't know. How can I tell ?

There is no pop up if this helps, only places to write down the user name and password.

Alon

Posted: Sun Dec 03, 2006 8:45 am
by ok
Maybe if you send POST headers you can get into the page...

Code: Select all

<?php
header("Content-Type: application/x-www-form-urlencoded");
//And...
$handle = fopen("http://example.com/?user=user&passwd=passwd", "rb"); 
?>

Posted: Wed Dec 06, 2006 3:46 am
by alon
Thanks for your help.
I tried it but it didn't work.

Alon

Posted: Wed Dec 06, 2006 3:56 am
by CoderGoblin
Using the CURL library is another option