An include for PHP session

1:14 AM 10/19/2018

This is nothing fancy but just a simple note I need to mention here for 2 reasons:

  1. Somehow I always forget how the code it :)
  2. It is almost always the start of coding a regular, cookie-based web page.

Source

//for higher security reason.
const DIR_SESS, '/my-private-session-directory');

//for having session (and javascript cookie) that may last for 7 days.
//set this parameter to 0 to make them expire whenever browser closes.
session_set_cookie_params(7 * 24 * 60 * 60);

session_save_path($_SERVER['DOCUMENT_ROOT'] . DIR_SESS);

session_start();
		

That's all

Comments