S
S
SANYAAAASSSS2018-06-29 17:04:25
PHP
SANYAAAASSSS, 2018-06-29 17:04:25

How to make a request from the server to the site and pass authorization?

I make a request to the site with authorization through the following: But, of course, it doesn’t let me in, how can I log in in this case?
file_get_contents("{ссылка}");

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pushkarev, 2018-06-29
@AXP-dev

With what authorization?
Through basic auth like this:

$auth = base64_encode("username:password");
$context = stream_context_create(['http' => ['header' => "Authorization: Basic $auth"]]);
$homepage = file_get_contents("http://example.com/file", false, $context );

A
alekssamos, 2018-06-30
@alekssamos

And for the usual (via html form) - I recommend using curl. Pass POST parameters and save cookie

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question