Skip to content

Instantly share code, notes, and snippets.

@YOzaz
Created October 13, 2015 13:37
Show Gist options
  • Select an option

  • Save YOzaz/6eee7035a0d83388320a to your computer and use it in GitHub Desktop.

Select an option

Save YOzaz/6eee7035a0d83388320a to your computer and use it in GitHub Desktop.
<?php namespace MyApp\Support\Memory;
trait SessionManager
{
/**
* Starts session if required
*
* @return void
**/
protected function startSession()
{
if ( version_compare(PHP_VERSION, '5.4.0', '>=') )
{
if (session_status() == PHP_SESSION_NONE)
{
@session_start();
}
}
else
{
if ( session_id() == '' )
{
@session_start();
}
}
// compatibility with old PHP versions
$_SESSION = isset($_SESSION) ? $_SESSION : [];
$_SESSION = is_array($_SESSION) ? $_SESSION : [ $_SESSION ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment