/** * save the current user id in the session. * * @param $user * a User object. The client is considered logged in as * <code>$user</code> when this function return. if NULL, the current * user is "logged out", meaning the session user id is unset. */ public static function current_is($user) { if (is_null($user)) { static::$current_user = NULL; if (session_active()) { unset($_SESSION['uid']); } } else { if ($user instanceof static) { static::$current_user = $user; if (session_active()) { $_SESSION['uid'] = $user->id; } } else { No2_Logger::err(get_called_class() . 'current_is: ' . 'Wrong user type: ' . get_class($user)); } } }
/** * Cross-site request forgery token generator. * * see https://en.wikipedia.org/wiki/Cross-site_request_forgery * * @return * A token as a string that is HTML / Javascript safe. */ function csrf_token() { if (!session_active()) { return ""; } if (!array_key_exists('_no2_csrf_token', $_SESSION)) { $_SESSION['_no2_csrf_token'] = sprintf("csrf.%s", uuidv4()); } return $_SESSION['_no2_csrf_token']; }
/** * redirect to the given location. * * * This method is designed to be called from the controller. * * @param $location * An URI string, the location to redirect to. * * @param $status * The HTTP status code. It should be a redirect status code. The default * is 303 See Other as this method is intended to be used by action * methods modifying the database by POST requests. * (see http://en.wikipedia.org/wiki/HTTP_303) */ public function redirect_to($location, $status = No2_HTTP::SEE_OTHER) { if (No2_HTTP::is_redirection($status)) { $this->set_status($status); } $this->__redirect_location = $location; // prepare the flash for the next call. if (session_active()) { $_SESSION['_no2_flash'] = $this->flash; } }
function estadoSession() { $value['estado'] = session_active(false); print json_encode($value); }
break; default: return false; break; } return false; } function str_cortar($texto, $cantidad_caracteres = 20) { // Inicializamos las variables return substr($texto, 0, $cantidad_caracteres); } if (!isset($_SESSION["ultimoAcceso"])) { $_SESSION["ultimoAcceso"] = date("Y-n-j H:i:s"); } session_active(false); function session_active($mensaje = true) { $fechaGuardada = $_SESSION["ultimoAcceso"]; $tiempo_transcurrido = strtotime(date("Y-n-j H:i:s")) - strtotime($fechaGuardada); if ($tiempo_transcurrido >= SESSION_MAX_TIME) { if ($mensaje) { echo "La sessión ha caducado"; } return false; } else { $_SESSION["ultimoAcceso"] = date("Y-n-j H:i:s"); if ($mensaje) { echo "Han pasado " . $tiempo_transcurrido . " [seg] desde la última vez que usaste la sessión"; } return true;