Closed nerdferby closed 4 years ago
Thanks!
What is the confusion that you’re experiencing? Are you creating Cookie
instances, calling the correct methods on them, finally calling Cookie#save
– but the cookie does not get stored by the client? Is this what’s happening?
Is this happening for you frequently? In practice, most clients should accept cookies, really.
And how would you check whether the client accepts cookies? Setting one and later checking if it’s still there (i.e. stored and sent to the server again)? That would require multiple requests.
What's happening is I'm not having much luck setting cookies. I'm getting no error message so it's hard to debug. In reflection, adding a method to test if the user accepts might be easier to implement in JavaScript.
$cookie = new Cookie("SID"); $cookie->setValue($session["encrypted_id"]); $cookie->setExpiryTime($session["expiration"]); $cookie->setPath("/"); $cookie->setHttpOnly(true); $cookie->save();
I think it’s unlikely that clients rejecting your cookies is the reason.
You could do a few things to help with debugging:
First, make sure that error reporting is enabled (including warnings and notices), and errors are either shown directly in the browser or saved to a log file that you watch.
Second, using the “Network” tab of your browser’s developer tools, inspect the HTTP headers of the response to the request where the cookies are set. Is there a Set-Cookie
header? What about the next request? Does it contain a Cookie
header now?
Sorry for the lat update. I've had some exams for my degree.
I found my issue to be that using Krumo's k()
function sends a header, meaning no cookies can be sent afterwards. I've fixed that now.
Glad to hear it was something else. Thank you!
This would be useful for testing if the user is able to accept cookies before attempting to use them. Thisi can prevent a lot of confusion for a new developer and the user