2012-07-11 29 views
0

如何顯示啓用了身份驗證的其他頁面的內容?顯示另一個啓用了身份驗證的頁面內容?

警告:file_get_contents(http://abc/report.cmd?report = 123):無法打開流:HTTP請求失敗! HTTP/1.1 401授權在//html/tracker/index2.php必需上線13

$file_path = 'http://abc/report.cmd?report=123'; 
    $content=file_get_contents($file_path); 
    echo $content; 
+1

[捲曲](http://php.net/手冊/ en/book.curl.php)可能會做你想做的。 – Bojangles 2012-07-11 19:49:40

回答

2

使用curl圖書館的認證

<?php 
// create a new cURL resource 
$curl = curl_init(); 

// set URL and other appropriate options 
curl_setopt($curl, CURLOPT_URL, "http://www.example.com/"); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC) ; 
curl_setopt($curl, CURLOPT_USERPWD, "username:password"); 

// grab URL and pass it to the browser 
curl_exec($curl); 

// close cURL resource, and free up system resources 
curl_close($curl); 
?> 
相關問題