/functions/global.php

Description

global.php

This includes code to update < 4.1.0 globals to the newer format It also has some session register functions that work across various php versions.

Constants
SQ_COOKIE = 4 (line 22)
SQ_FORM = 6 (line 24)
SQ_GET = 1 (line 19)
SQ_INORDER = 0 (line 18)
SQ_POST = 2 (line 20)
SQ_SERVER = 5 (line 23)
SQ_SESSION = 3 (line 21)
Functions
check_php_version (line 36)

returns true if current php version is at mimimum a.b.c

Called: check_php_version(4,1)

bool check_php_version ([mixed $a = '0'], [mixed $b = '0'], [mixed $c = '0'])
check_sm_version (line 52)

returns true if the current internal SM version is at minimum a.b.c These are plain integer comparisons, as our internal version is constructed by us, as an array of 3 ints.

Called: check_sm_version(1,3,3)

bool check_sm_version ([mixed $a = 0], [mixed $b = 0], [mixed $c = 0])
list_files (line 476)

Find files and/or directories in a given directory optionally limited to only those with the given file extension. If the directory is not found or cannot be opened, no error is generated; only an empty file list is returned.

  • return: The requested file/directory list(s).
  • since: 1.5.2
array list_files (string $directory_path, [string $extension = ''], [boolean $return_filenames_only = TRUE], [boolean $include_directories = TRUE], [boolean $directories_only = FALSE], [boolean $separate_files_and_directories = FALSE])
  • string $directory_path: The path (relative or absolute) to the desired directory.
  • string $extension: The file extension filter (optional; default is to return all files (dirs).
  • boolean $return_filenames_only: When TRUE, only file/dir names are returned, otherwise the $directory_path string is prepended to each file/dir in the returned list (optional; default is filename/dirname only)
  • boolean $include_directories: When TRUE, directories are included (optional; default DO include directories).
  • boolean $directories_only: When TRUE, ONLY directories are included (optional; default is to include files too).
  • boolean $separate_files_and_directories: When TRUE, files and directories are returned in separate lists, so the return value is formatted as a two-element array with the two keys "FILES" and "DIRECTORIES", where corresponding values are lists of either all files or all directories (optional; default do not split up return array).
make_seed (line 361)

session_regenerate_id replacement for PHP < 4.3.2

This code is borrowed from Gallery, session.php version 1.53.2.1

void make_seed ()
php_combined_lcg (line 366)
void php_combined_lcg ()
php_self (line 414)

php_self

Creates an URL for the page calling this function, using either the PHP global REQUEST_URI, or the PHP global PHP_SELF with QUERY_STRING added. Before 1.5.1 function was stored in function/strings.php.

  • return: the complete url for this page
  • since: 1.2.3
string php_self ()
session_regenerate_id (line 388)
void session_regenerate_id ()
sm_print_r (line 555)

Print variable

sm_print_r($some_variable, [$some_other_variable [, ...]]);

Debugging function - does the same as print_r, but makes sure special characters are converted to htmlentities first. This will allow values like <[email protected]> to be displayed. The output is wrapped in <pre> and </pre> tags. Since 1.4.2 accepts unlimited number of arguments.

  • since: 1.4.1
void sm_print_r ()
sqgetGlobalVar (line 155)

Search for the var $name in $_SESSION, $_POST, $_GET, $_COOKIE, or $_SERVER and set it in provided var.

If $search is not provided, or if it is SQ_INORDER, it will search $_SESSION, then $_POST, then $_GET. If $search is SQ_FORM it will search $_POST and $_GET. Otherwise, use one of the defined constants to look for a var in one place specifically.

Note: $search is an int value equal to one of the constants defined above.

Example: sqgetGlobalVar('username',$username,SQ_SESSION); // No quotes around last param, it's a constant - not a string!

  • return: whether variable is found.
bool sqgetGlobalVar (mixed $name, mixed &$value, [mixed $search = SQ_INORDER], [mixed $default = NULL], [ $typecast = false])
  • $typecast
sqsession_destroy (line 229)

Deletes an existing session, more advanced than the standard PHP session_destroy(), it explicitly deletes the cookies and global vars.

WARNING: Older PHP versions have some issues with session management. See http://bugs.php.net/11643 (warning, spammed bug tracker) and http://bugs.php.net/13834. SID constant is not destroyed in PHP 4.1.2, 4.2.3 and maybe other versions. If you restart session after session is destroyed, affected PHP versions produce PHP notice. Bug should be fixed only in 4.3.0

void sqsession_destroy ()
sqsession_is_active (line 261)

Function to verify a session has been started. If it hasn't

start a session up. php.net doesn't tell you that $_SESSION (even though autoglobal), is not created unless a session is started, unlike $_POST, $_GET and such

void sqsession_is_active ()
sqsession_is_registered (line 121)

Checks to see if a variable has already been registered in the session.

  • return: whether the var has been registered
bool sqsession_is_registered (string $name)
  • string $name: the name of the var to check
sqsession_register (line 92)

Add a variable to the session.

void sqsession_register (mixed $var, string $name)
  • mixed $var: the variable to register
  • string $name: the name to refer to this variable
sqsession_start (line 273)

Function to start the session and store the cookie with the session_id as

HttpOnly cookie which means that the cookie isn't accessible by javascript (IE6 only)

void sqsession_start ()
sqsession_unregister (line 106)

Delete a variable from the session.

void sqsession_unregister (string $name)
  • string $name: the name of the var to delete
sqsetcookie (line 298)

Set a cookie

void sqsetcookie (string $sName, string $sValue, [int $iExpire = false], [string $sPath = ""], [string $sDomain = ""], [boolean $bSecure = false], [boolean $bHttpOnly = true], [ $bFlush = false])
  • string $sName: The name of the cookie.
  • string $sValue: The value of the cookie.
  • int $iExpire: The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch.
  • string $sPath: The path on the server in which the cookie will be available on.
  • string $sDomain: The domain that the cookie is available.
  • boolean $bSecure: Indicates that the cookie should only be transmitted over a secure HTTPS connection.
  • boolean $bHttpOnly: Disallow JS to access the cookie (IE6 only)
  • $bFlush
sqsetcookieflush (line 351)

Send the cookie header

Cookies set with sqsetcookie will bet set after a sqsetcookieflush call.

void sqsetcookieflush ()
sqstripslashes (line 73)

Recursively strip slashes from the values of an array.

void sqstripslashes (mixed &$array)

Documentation generated on Sat, 07 Oct 2006 16:11:26 +0300 by phpDocumentor 1.3.0RC6