Skip to content

Instantly share code, notes, and snippets.

@JezDriver
Created June 24, 2025 01:47
Show Gist options
  • Select an option

  • Save JezDriver/30e69de0bcefe948735e4d16d22fa965 to your computer and use it in GitHub Desktop.

Select an option

Save JezDriver/30e69de0bcefe948735e4d16d22fa965 to your computer and use it in GitHub Desktop.
Check if a session exists and a variable has been set #php
<?
function isNewSession() {
if(session_id() == '' || !isset($_SESSION) || session_status() === PHP_SESSION_NONE) {
// session isn't started
session_set_cookie_params(3600,"/"); // 1 hour
session_start();
}
if (!isset($_SESSION['new_session'])) {
$_SESSION['new_session'] = true;
}
else {
$_SESSION['new_session'] = false;
}
return $_SESSION['new_session'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment