2
you very likely already know and/or have seen that old apache authentication system (htpasswd | image below).
Well, I need to create a code that sends the login and password to the form and goes straight to the page. No need to type everything manually.
I know it is possible to do this in html forms using CURL, but in this one I have no idea.
Note: I want to realize login automatic, do not create that window. If anyone can help I’d appreciate it.
======================== Example using CURL and an HTML form:
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://www.sitecomsistemaauth.com/index.php');
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, 'meulogin=abc&senha=123');
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1;
// Variável que armazena o HTML renderizado após o login;
$sendPost = curl_exec ($curl);
// REGEX PARA PEGAR STRINGS DA PÁGINA
$pattern = '@(.*)@';
$target = $sendPost;
$matches = array();
$finalContent = $normalMode($pattern,$target,$matches);
// Retorna todos os resultados encontrado;
echo "<pre>";
var_dump($finalContent,$matches);
curl_close ($curl);
?>
This I can do in HTML form, but how to do in a basic "form" http Authentication?.
Is that something you want? http:///user:password@domain:port?
– user6406
Hi, thanks for answering. So, I had already tried this method only it has some disadvantages, for example: It doesn’t work in IE and if I use inside php it would have to be something like "header("Location: http://user:password@domain")" and in this case it would go straight to the page and the php code would end. I want something to work the page after you understand? type store the page that comes after login in a variable and use regular expressions to manipulate the content.
– Jean
So I didn’t understand your question. You could edit to make it clearer.
– user6406
I edited it. Actually the doubt is very simple, maybe I’m actually expressing myself incorrectly. If I send the parameters via URL as in the example, the window will appear asking for login and password in the same way.
– Jean
There is a link: (http://solvedstack.com/questions/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl) but I don’t understand how it works.
– Jean