OK - Simply, I am creating a site that must incorporate a current page, protected having a simple .htaccess/.htpasswd script.
How do i pass the username/password towards the receiving site using PHP?
Thanks ahead of time for the help!!!
UPDATE - I believe I might have over-complicated the question. What I am requiring to complete is basically:
<a href="http://username:firstname.lastname@example.org/" target="_blank">The link<a>
Which, really, works perfectly in everything but For Example I am golden basically will find a far more universal, simple solution.
Thanks ahead of time for the help, all!
To be sure with alxp that you ought to become familiar with cURL. The fundamental gist is the fact that when utilizing HTTP Fundamental Auth, qualifications are sent like a base64 encoded string within the headers. Here is a simple example using PHP's cURL extension:
$url = '...'; $username = '...'; $password = '...'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Basic " . base64_encode($username . ":" . $password) )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $result = curl_exec($ch); print $result;
Please bear in mind this is example code and consists of no error checking, etc.
If you work with the
file_get_contents function to download the page, you should use something similar to this:
$data = file_get_contents('http://username:email@example.com/path/');
You will be better off should you become familiar with the curl library, a great introduction are available here, including how you can submit a suername and password.
You are able to pass the account information in plain-text using a simple http redirect, within the format
However, you most likely should not - some browsers now clearly bother you for confirmation once they check this out syntax.
You are able to hide this in the user however, by loading the above mentioned URL with file_get_contents() and dumping the outcomes towards the browser. This will not work when the HTML creation of the page uses relative links to exterior files (images/js/css) on its server.