A: We didn't provide one. You can create your own in a text editor, or you can just have your code create the file when you add users.
Q: What if the user submits a really long string into the to-do list? Should I truncate it or limit its width?
A: You don't have to worry about this.
Q: Does the order we save our list in matter?
A: Yes, it does matter; the server should save it and display it in the order that the items were added.
Q: Should I use a GET or POST for my HTML forms?
A: You should make an appropriate choice. Remember what GET and POST are supposed to be used for.
Q: After I redirect from one page to another, my GET/POST query parameter array is empty. Why?
A: The $_GET and $_POST array contents don't survive across a redirect. If you need to carry state across a redirect, store it in session variables.
Q: If the text file doesn't exist, are we supposed to create it?
A: Yes. According to the PHP web site, file_put_contents() will create a file if it's not already there.
Q: When i tried to use file_put_contents, the permission is denied even though I have set the permission in the webster to be ok to write, so how could i get the permission to write in the file.
A: Make sure you have checked the boxes for the Write permissions on the file, and if that doesn't work, make sure that your directory for the assignment (hw5) has write and execute permissions turned on. Execute permission on a directory allows someone to enter that directory and view its contents. If you are getting "permission denied" messages, try changing the read/write permissions on your hw5 folder in Webster.
Q: How can I indicate an error in my PHP code? How can I redirect?
A: Errors can be indicated by calling die. Use the header function to redirect.
Q: My redirect doesn't work. Why not?
A: Any calls to PHP's header function must come before you produce any output from your file. If you output any HTML and then try to set a header, PHP will complain. So do any code/logic involving headers first. Keep in mind that even just having whitespace from being in non-HTML mode, or an HTML comment at the top of your file, or including a file full of HTML, will count as "output".
Q: Why aren't my cookies setting properly? I think I am creating them the right way, but they aren't there.
A: Any calls to PHP's setcookie function must come before you produce any output from your file. If you output any HTML and then try to set a cookie, PHP will complain. So do any code/logic involving headers first. Keep in mind that even just having whitespace from being in non-HTML mode, or an HTML comment at the top of your file, or including a file full of HTML, will count as "output".
Q: How do I remember whether the user is logged in? How do I log the user out?
A: Store information as a PHP session.
You should decide what info should be saved in the session, but save enough to know that the user logged in successfully.
When they log out, destroy the session to 'forget' the data that you saved.
Q: I wrote the PHP code to create a session and remember some session data, but then the next page can't find the data. What is wrong?
A: You have to call session_start at the start of every page that uses sessions.
The session_start function doesn't create a new empty session every time you call it.
It just initializes PHP's session management system and creates/fills in the $_SESSION array for you.
Q: My "log out" code doesn't work. I followed the examples from the book/slides, but I can't get it to "forget" the user.
A: One weird thing about sessions is that you have to call session_start to initialize PHP's session system before you can call session_destroy.