Reputation: 1
I'm trying to get the source of a file using PHP and the file_get_contents function.
The problem is that the website requires a login. I thought that this could be bypassed by logging into the site first and then use the file_get_contents function but this is not the case. The page that the function returns is the login page.
This is the code:
<?php
if (isset($_GET['getroster'])){
$file = stripslashes(file_get_contents('https://intranet.hlf.de/custom/cddTUB.asp?show=1'));
print ($file);
}
?>
As you can see when running this function, or when going to the url, it requests a username, password and company from a dropdown list.
Is it possible to pass these values to the page by using this or any other PHP function. Or maybe doing it in a totally different way?
Upvotes: 0
Views: 388
Reputation: 1047
Any change you could post an example of how to do that Daniel?
There wouldn't be an option of creating a login like form which sents the user information to the page to login automatically? Read something about the stream_context_create function which could do a login by sending header information but I really wouldn't where to start. The examples posted about that only give username and password but I ofcourse have a third option to post to the authentication page!
Upvotes: 0
Reputation: 123548
You have to send the correct cookies. If you can use curl, then the script on this page should help. You can also take a look at this SO question (it's slightly different from your case since it's reusing browser cookies to make the request).
Upvotes: 0
Reputation: 8382
The cookies in your browser, and the cookies can be sent with PHP are completely unrelated.
Using curl you can set the options CURLOPT_COOKIEJAR
and CURLOPT_COOKIEFILE
to specify a file in which cookies should be stored and loaded from.
Doing that you will first have to make a request that does the login (this will get you the cookie). Next you can do the request you wanted to do as a logged in user (because now curl has the cookies).
Upvotes: 2