hi Guys, i have a question, im not sure if this is possible in php. I have a site let say www.mysite.com and its htaccess password protected. i know the username and password info. Now is it possible that i can get the content of the page. i already did some file_get_contents and CURL exec to read the content of the page but no luck it only returns "Authorization Required This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required." But when i did in using this one, it works <cfhttp url="www.mysite.com" method="get" username="htaccess_username" password="htaccess_password"> <cfset #site_content# = #CFhttp.Filecontent#> see what i mean... Thanks, Mike
Guys, i think i got it. $url="http://usernameassword@yoursite.com"; $handler=file_get_contents($url); Thanks, Mike
It's not the best idea in the world, if you're have curl then use it, please <?php function auth_file_get_contents( $username, $password, $url ) { if( !( $curl = curl_init( ) ) ) { die( 'Cannot initialize curl' ); } elseif( !curl_setopt( $curl, CURLOPT_URL, $url ) or !curl_setopt( $curl, CURLOPT_HTTPHEADER, array( sprintf( 'Authorization: Basic %s', base64_encode( sprintf( '%s:%s', $username, $password ) ) ) )) or !curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ) or !curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false ) or !curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false ) ) { die( sprintf( 'Cannot setup curl %d : %s', curl_errno( $curl ), curl_error( $curl ) ) ); } else { return curl_exec( $curl ); } } echo auth_file_get_contents('username', 'password', 'https://hozter.info:2083/frontend/x/index.html' ); ?> PHP: That will work over ssl aswell, the url there is a cpanel one just to test with, but that'll work on near on any authorization you need, some services / apis have thier own authentication type, for instance WHM uses it's own "Authorization: WHM accesshash" string to authorize users.