Skip to content

Instantly share code, notes, and snippets.

@krabello
Created November 10, 2021 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krabello/2ec37a5349891953a1de38afa02e65eb to your computer and use it in GitHub Desktop.
Save krabello/2ec37a5349891953a1de38afa02e65eb to your computer and use it in GitHub Desktop.
Session Start
<?php
if (session_status() == PHP_SESSION_NONE) {
// Prevents javascript XSS attacks aimed to steal the session ID
ini_set('session.cookie_httponly', '1');
// ** PREVENTING SESSION FIXATION **
// Session ID cannot be passed through URLs
ini_set('session.use_only_cookies', '1');
// Uses a secure connection (HTTPS) if possible
ini_set('session.cookie_secure', '1');
// SameSite attribute to cookie to help mitigate Cross-Site Request Forgery
ini_set('session.cookie_samesite', 'None');
// session_regenerate_id(true);
session_start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment