how I can give my credentials with get_contents? php
I have looked at some examples and they use Curl in php etc but I just want a simple command that passes my credentials to a site so it can login and give me access to download a file. Current problem is when I try to use get_contents I get stuck at login page because it needs a login before it can allow a download so isnt there a way to send my login info before get_contents in php? Thanks
for example we can assume the website is located at w开发者_如何学Goww.confluence.com
You're out of luck. file_get_contents()
can only get content, hence the name. You can try to authenticate via the get syntax for standard authentication, like http://username:password@example.com
.
If you have to post your credentials via HTTP POST, you'll have to use curl.
The problem is that when you log in the server send to your browser a cookies that your browser automatically stores.
With file_get_content()
you can actually pass cookies ( the third context
parameter of file_get_content() can handle this).
Have a look at stream context create.
By the way, you need to first send your login info to the login page (with curl
), when you recive cookies back, pass them as option to file_get_content()
and the trick is done.
If the server is using a login system different from cookies let us know, so we can help you
精彩评论