You would add a 'remember me' checkbox to your login form. At the point in your login code where the user has successfully logged in, you would test if your 'remember me' checkbox form field has been checked.
You would then generate a unique token to store in the remember me cookie and also store this in your user table (you would need to add a column specifically to hold the token value.)
You should not generate the value you store in the cookie from any of the user information because that value will be static for any user and if someone gets a hold of that value they will be able to use it to login until the original user value it is generated from is changed. Would you want to require your users to change their password or username or to regenerate a new salt string just to stop someone who has gotten a hold of someone else's 'remember me' cookie value?
By generating a unique token, that is not a fixed value for any user, it can be regenerated at any time and you make it harder for the bad guys. Also, by generating it and storing it in a field in the database table, you can clear it in that table when someone logs out or to disable a value where it is know that the value has been gotten a hold of by someone else.
You would change your 'page protection' logic so that if the 'logged in session' value is not set, you get the user's id using the 'remember me' cookie value and set the logged in session value the same as if the user had just successful logged in.
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.