Php có chuyển đổi không?

Guide to URL paths...

Data: $_SERVER['PHP_SELF']
Data type: String
Purpose: The URL path name of the current PHP file, including path-info [see $_SERVER['PATH_INFO']] and excluding URL query string. Includes leading slash.
Caveat: This is after URL rewrites [i.e. it's as seen by PHP, not necessarily the original call URL].
Works on web mode: Yes
Works on CLI mode: Tenuous [emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved]

Data: $_SERVER['SCRIPT_NAME']
Data type: String
Purpose: The URL path name of the current PHP file, excluding path-info and excluding URL query string. Includes leading slash.
Caveat: This is after URL rewrites [i.e. it's as seen by PHP, not necessarily the original call URL].
Caveat: Not set on all PHP environments, may need setting via preg_replace['#\.php/.*#', '.php', $_SERVER['PHP_SELF']].
Works on web mode: Yes
Works on CLI mode: Tenuous [emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved]

Data: $_SERVER['REDIRECT_URL']
Data type: String
Purpose: The URL path name of the current PHP file, path-info is N/A and excluding URL query string. Includes leading slash.
Caveat: This is before URL rewrites [i.e. it's as per the original call URL].
Caveat: Not set on all PHP environments, and definitely only ones with URL rewrites.
Works on web mode: Yes
Works on CLI mode: No

Data: $_SERVER['REQUEST_URI']
Data type: String
Purpose: The URL path name of the current PHP file, including path-info and including URL query string. Includes leading slash.
Caveat: This is before URL rewrites [i.e. it's as per the original call URL]. *
*: I've seen at least one situation where this is not true [there was another $_SERVER variable to use instead supplied by the URL rewriter], but the author of the URL rewriter later fixed it so probably fair to dismiss this particular note.
Caveat: Not set on all PHP environments, may need setting via $_SERVER['REDIRECT_URL'] . '?' . http_build_query[$_GET] [if $_SERVER['REDIRECT_URL'] is set, and imperfect as we don't know what GET parameters were originally passed vs which were injected in the URL rewrite] --otherwise-- $_SERVER['PHP_SELF'] . '?' . http_build_query[$_GET].
Works on web mode: Yes
Works on CLI mode: No

Data: $_SERVER['PATH_INFO']
Data type: String
Purpose: Find the path-info, which is data after the .php filename in the URL call. It's a strange concept.
Caveat: Some environments may not support it, it is best avoided unless you have complete server control
Works on web mode: Yes
Works on CLI mode: No

Note that if something is not set it may be missing from $_SERVER, or it may be blank, so use PHP's 'empty' function for your test.

The following code shows how the PHP session works. The function my_session_start[] does almost the same thing as session_start[].

________số 8_______

my_session_start[];

echo '

session id: '.my_session_id[].'

';

echo '

________0';

$now = date['H:i:s'];
if [isset[$_SESSION['last_visit_time']]] {
  echo '

Last Visit Time: '.$_SESSION['last_visit_time'].'

';
}
echo '

Current Time: '.$now.'

';

$_SESSION['last_visit_time'] = $now;

function my_session_start[] {
  global $phpsessid, $sessfile;

  if [!isset[$_COOKIE['PHPSESSID']] || empty[$_COOKIE['PHPSESSID']]] {
    $phpsessid = my_base32_encode[my_random_bytes[16]];
    setcookie['PHPSESSID', $phpsessid, ini_get['session.cookie_lifetime'], ini_get['session.cookie_path'], ini_get['session.cookie_domain'], ini_get['session.cookie_secure'], ini_get['session.cookie_httponly']];
  } else {
    $phpsessid = substr[preg_replace['/[^a-z0-9]/', '', $_COOKIE['PHPSESSID']], 0, 26];
  }

  $sessfile = ini_get['session.save_path'].'/sess_'.$phpsessid;
  if [is_file[$sessfile]] {
    $_SESSION = unserialize[file_get_contents[$sessfile]];
  } else {
    $_SESSION = array[];
  }
  register_shutdown_function['my_session_save'];
}

function my_session_save[] {
  global $sessfile;

  file_put_contents[$sessfile, serialize[$_SESSION]];
}

function my_session_id[] {
  global $phpsessid;
  return $phpsessid;
}

function my_random_bytes[$length] {
  if [function_exists['random_bytes']] {
      return random_bytes[$length];
  }
  $randomString = '';
  for [$i = 0; $i < $length; $i++] {
      $randomString .= chr[rand[0, 255]];
  }
  return $randomString;
}

function my_base32_encode[$input] {
  $BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
  $output = '';
  $v = 0;
  $vbits = 0;
  for [$i = 0, $j = strlen[$input]; $i < $j; $i++] {
    $v > $vbits];
      $v &= [[1 0] {
    $v

Chủ Đề