You are here

function _ip_geoloc_set_session_value in IP Geolocation Views & Maps 7

Set a value to the user's SESSION.

Parameters

string $name: if FALSE all IPGV&M session variables are deleted; if NULL the array of all IPGV&M session variables is returned.

mixed $value: The value to set. Use NULL to wipe the existing value.

Return value

array|null The requested or all session variables from ip_geoloc

11 calls to _ip_geoloc_set_session_value()
ip_geoloc_current_location_ajax_recipient in ./ip_geoloc.module
Data recipient for javascript function getLocation().
ip_geoloc_erase_session in ./ip_geoloc.admin.inc
Erase geoloc data from session.
ip_geoloc_get_current_location in ./ip_geoloc_api.inc
Uses AJAX to return in $_POST info about the visitor's current location.
ip_geoloc_init in ./ip_geoloc.module
Implements hook_init().
ip_geoloc_log_errors in ./ip_geoloc.module
Log errors via the watchdog.

... See full list

File

./ip_geoloc.session.inc, line 23
ip_geoloc.session.inc

Code

function _ip_geoloc_set_session_value($name, $value = NULL) {
  if (!variable_get('ip_geoloc_allow_session_storage', TRUE)) {
    return NULL;
  }
  if (module_exists('context_session') && $name == 'location') {
    _ip_geoloc_set_location_on_context_session($value);
  }
  if (!module_exists('session_cache')) {
    if ($name === FALSE) {
      unset($_SESSION['ip_geoloc']);
    }
    elseif (isset($name)) {
      $_SESSION['ip_geoloc'][$name] = isset($_SESSION) && isset($_SESSION['ip_geoloc'][$name]) && is_array($_SESSION['ip_geoloc'][$name]) && is_array($value) ? array_merge($_SESSION['ip_geoloc'][$name], $value) : $value;
    }
    return isset($_SESSION) && isset($_SESSION['ip_geoloc']) ? $_SESSION['ip_geoloc'] : NULL;
  }
  if ($name === FALSE) {
    session_cache_set('ip_geoloc', NULL);
    return NULL;
  }
  $variables = session_cache_get('ip_geoloc');
  if (isset($name)) {

    // Merge/override the session with the supplied value
    $variables[$name] = isset($variables[$name]) && is_array($variables[$name]) && is_array($value) ? array_merge($variables[$name], $value) : $value;
    session_cache_set('ip_geoloc', $variables);
  }
  return $variables;
}