Jump to content

Recommended Posts

I'm in the middle of a school project in a programming class and i ran into some problems.

 

I'm trying to read the source from my schools site, with a list of all my homework.

I wan't to read this list and display it on my own site.

 

The problem is that I can't find any way to read the source.

 

 

The file im trying to read is:

http://htx.ots.dk/otgnet/adm/restr/portfolio/listeafleveringer.asp

 

I have tried the following with no success:

 

//cURL script

$url = 'http://htx.ots.dk/otgnet/adm/restr/portfolio/listeafleveringer.asp';
$user="******";
$pass="******";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11');
$contents = curl_exec($ch);
if ($contents === false) {
   trigger_error('Failed to execute cURL session: ' . curl_error($ch), E_USER_ERROR);
}
print $contents;

With this cURL script I can get the source, but I'm getting the source for the unauthorized site with the following error:

401 - Unauthorized: Access is denied due to invalid credentials

But the username and password isn't invalid, because I can log in with those manualy.

 

 

I have also tried a file_get_contents with a context, but then i just get this error:

 

Warning: file_get_contents(http://htx.ots.dk/otgnet/adm/restr/portfolio/listeafleveringer.asp) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /var/www/******.com/public_html/test/index.php on line 34

 

The file_get_contents script:

 

$url = 'http://htx.ots.dk/otgnet/adm/restr/portfolio/listeafleveringer.asp';
$user="******";
$pass="******";

$cred = sprintf('Authorization: Basic %s',
    base64_encode("$user:$pass") );
$opts = array(
    'http'=>array(
    'method'=>'GET',
    'header'=>$cred)
);
$ctx = stream_context_create($opts);
$validate=file_get_contents($url,false,$ctx);
print $validate;

 

 

What am I doing wrong? Are there any other ways to get the source from a website?

Looking at the headers you'll see

WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM

 

So this is not HTTP Basic authentication. NTLM is the NT LAN Manager, so your school is using the Windows domain's authentication framework.

 

On a school I once went to they used that for their intranet as well. I remember that in Internet Explorer you would have to explicitly specify the domain name, so it would be like domain\user instead of just user. You can try to see if that works. Otherwise, try to read up on NTLM authentication to see if you have to go through some weird hoops to get in.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.