Hey! I want to use cookies,but when I used it didn't work can anyone help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Hey! I want to use cookies,but when I used it didn't work can anyone help me

https://code.sololearn.com/wjMq5V8fHruB/?ref=app

13th Apr 2023, 5:35 AM
Girish Sahu
Girish Sahu - avatar
3 Answers
+ 6
Sure! I reviewed your code, and it looks like there is a small mistake in the way you are setting the cookie expiration time. Currently, you are using the time() function to set the cookie expiration time to one hour from the current time: setcookie("user_input", $user_input, time()+3600); However, this will cause the cookie to expire exactly one hour after it is set, regardless of when the user initially accessed the page. To set the cookie to expire one hour after the user initially accessed the page, you can use the following code: setcookie("user_input", $user_input, time()+3600, "/");
13th Apr 2023, 8:04 AM
Sadaam Linux
Sadaam Linux - avatar
+ 6
This sets the cookie expiration time to one hour after the current time, but also includes the optional fourth parameter of the setcookie() function, which sets the cookie path to the root directory (/). This ensures that the cookie is available to all pages on your site, not just the current directory. With this change, your code should work correctly and remember the user input for one hour after the user initially accessed the page.
13th Apr 2023, 8:04 AM
Sadaam Linux
Sadaam Linux - avatar
0
Sadaam Linux actually its not storing data(cookies
13th Apr 2023, 2:21 PM
Girish Sahu
Girish Sahu - avatar