I have 2 pages: login.php and index.php
When writting localhost/mysite/login.php and writting a username and password in a form, a cURL request using CURLOPT_HTTPAUTH = CURLAUTH_DIGEST and CURLOPT_USERPWD = 'user:pass' will be passed to another file that will authenticate the user with those credentials using HTTP DIGEST AUTH, and will return 200 for success or 401 for wrong credentials.
If it gets a 200 code, login.php will redirect to index.php, which will make a cURL request too to that same digest file, but without CURLOPT_HTTPAUTH or CURLOPT_USERPWD. The idea is that, since I already did this on login.php, those digest credentials should be stored on the user browser, but it isn't. So index.php will end up asking for credentials AGAIN, this is the problem.
Some people has recommended me to use CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR, but no one has explained me how does that work? I understand that CURLOPT_COOKIEFILE is for retrieving cookies info, and CURLOPT_COOKIEJAR is for saving them.
So the questions are this:
1) The route for that cookie file (ex. '/tmp/cookies.txt'), where is that? what exactly is /tmp/cookies.txt? in the same level as login.php? or in C:/? also, should I create this file beforehand? or is it created automatically?
2) Is that file on the server, or on the client? if on the server, how am I to know which cookie is from which user, so that Y user doesn't end up using X user credentials to log in.
3) Also, when using those cookies options, what am I saving exactly? In the authentication page should I manually create a cookie to be stored on that file? if so, what cookie? I need to keep the Digest Auth Credentials, which I think is a header with nonce, cnonce, nc, username, response, etc... Not sure if this is actually the way around it.
Thanks in Advance