I am new to PHP and I am not familiar with session management. I am creating a e-commerce website so I need to create a hack-proof session. For that I googled a lot about how to prevent session hijacking. The sources I read suggest that I include in my code these functions:
\\some saying to use this
session_start();
session_regenerate_id(true);
\\some others saying to use this
session_start();
session_regenerate_id();
…and also to use HTTPS/TLS. In another of the stackoverflow post I came across this stuff:
- use enough random input for generating the session ID (see session.entropy_file, session.entropy_length, and session.hash_function)
- use HTTPS to protect the session ID during transmission
- store the session ID in a cookie and not in the URL to avoid leakage though Referer (see session.use_only_cookies)
- set the cookie with the HttpOnly and Secure attributes to forbid access via JavaScript (in case of XSS vulnerabilities) and to forbid transmission via insecure channel (see session.cookie_httponly and session.cookie_secure)
But I cannot understand those. It’s just theory to me; instead what I would like to have is some PHP code does those things—or any website having those things implemented, with PHP code that I could see and us as an example (and that ideally had some explanation to go along with it).