Help get this topic noticed by sharing it on Twitter, Facebook, or email.

PHP & MySQL: The Missing Manual. Authorization and Sessions Chapter. Sample code problems.

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?
1 person has
this question
+1
Reply