RSR Posted August 8, 2009 Share Posted August 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169339-get-source-from-a-site-with-login-access/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169339-get-source-from-a-site-with-login-access/#findComment-894030 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.