title: Creating a secure login using sessions and cookies in PHP
body: <p>I am making a login script that I would like to be as secure as possible. Problem is, security seems to be a never ending battle. So essentially, I am looking for suggestions and improvements to my ideas.</p>
  
  <p>What I have is a login based solely on sessions. Anytime the session information changes, <code>session_regenerate_id()</code> is called to avoid obvious hijacking attempts.</p>
  
  <p>When the session is not set, I check a cookie for valid login, and on success, I update the session.</p>
  
  <p>I attempt to secure the cookie by adding a hash value along with a piece of unique user information (like username or id). This hash is comprised of various information, including the username/id, undecipherable password hash, part of the IP address, etc. By extracting the username/id from the cookie, I can make a new hash from the valid user information and compare that with the hash in the cookie. My hopes here are to prevent fake cookies and cookie hijacking (unless they also spoof the IP address).</p>
  
  <p><strong>EDIT</strong> Assume that the login itself will be done via HTTPS/SSL, so the transfer is (reasonably) secure.</p>
  
  <p>Am I on the right track? What else can be done to secure my login?</p>
  
  <p>Thanks for the help!</p>