PHP & MySQL: The Missing Manual (first and second edition sample codes)
I tried to test sample code of the chapter "Authorization and Sessions". I found this problem. I was not able to navigate to show_users.php after sign up. I got to singup.php with the message "You must login to see this page."
The whole way I passed through sample code contains these pages in order
index.hrml -> singup.php -> create_user.php -> show_user.php. What I saw that first call of fucntion session_start() was only in the show_user.php before function authorize_user(). In the previous file create_user.php there's no session_start() function. But the function authorize_user() in the file show_user.php didn't allow to navigate to show_user.php because it tried to find $_SESSION['user_id'], but could not find it. This value wasn't set in any php scripts before.
I solved this problem adding in the create_user.php these two strings session_start(); $_SESSION['user_id'] = mysql_insert_id(); before function header("Location: show_user.php?user_id=" . mysql_insert_id());
Could you explain why it doesnt work without adding these two string. Is it an error in sample code?
Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I have forwarded your question on to our Book Tech staff, so they can help you find a solution. If you ever have any questions or issues with the content of a title, you can also contact them directly at email@example.com or call them at:
1-707-827-7019 (outside the USA)
7:30 am to 5:00 PST
Customer Service Representative