Segmentar URI

Segmentar URI

#etiqueta de control
function f_segmentar_uri () {
/* */
  $uriserverprotocol = $_SERVER["SERVER_PROTOCOL"];
  $urihttphost = $_SERVER["HTTP_HOST"];
  $uriserverport = $_SERVER["SERVER_PORT"];
  $uridocumentroot = $_SERVER["DOCUMENT_ROOT"];
  $urifilename = $_SERVER["SCRIPT_FILENAME"]; # uri del archivo real en el sistema
  $uriscriptname = $_SERVER["SCRIPT_NAME"];  # uri web del archivo real ejecutado
  $urirequest = f_limpiardobles ($_SERVER["REQUEST_URI"]); # uri web logico completo visualizado
  $uriphpself = f_limpiardobles ($_SERVER["PHP_SELF"]); #  uri web logico ejecutado
  $uriscriptdirectory = dirname ($uriscriptname); # directorio web logico
  $uriscriptfile = basename ($uriscriptname); # nombre del archivo real
  $uriscriptexecution = $uriscriptname; # directorio web logico
  $uriexecutiondirectory = "/"; # directorio relativo
  $executionfile0 = "";
  $executionfile = "inicio"; # componente ejecutado
  $consultas = ""; # consultas
/* */
 
/* */
  if ($uriscriptname != $urirequest) {
  /* */
    # la uri absoluta no es igual al nombre script
    # entonces no imprime nada
    $uriscriptexecution = $uriscriptname;
    if (!strstr ($urirequest, $uriscriptname)) {
      #  en la uri absoluta no se encuentra el path absoluto nombre del script
      $uriscriptexecution = dirname ($uriscriptname);
    }
    else { # la uri absoluta contiene el nombre del script
    }
    $uriexecutionaray = f_directorio_relativo ($urirequest, $uriscriptexecution);
    $execusiondate = $uriexecutionaray[0];
    $uriexecutiondirectory = dirname ($execusiondate);
    $executionfile0 = basename ($execusiondate);
    $executionfile = basename ($execusiondate);
    $consultas = $uriexecutionaray[1];
  /* */
  }
  else {
  /* */
    # la uri absoluta corresponde al scrip ejecutado
    $uriscriptexecution = $uriscriptname;
    $uriexecutiondirectory = "/";
  /* */
  }
  if ($executionfile == "") { $executionfile = "inicio"; $executionfile0 = ""; }
/* */
  $urifull = "".f_protocolos_web ($uriserverprotocol)."://".$urihttphost.":".$uriserverport."".$urirequest."";
  return array ("URIFULL" => $urifull, "PROTOCOLO" => $uriserverprotocol, "EQUIPO" => $urihttphost, "PUERTO" => $uriserverport, 
"PATHHTTPD" => $uridocumentroot, "SISPATH" => $urifilename, "WEBARCHIVO" => $uriscriptname, 
"URILOGICA" => $urirequest, "WEBLOGICO" => $uriphpself, "REALDIR" => $uriscriptdirectory, 
"REALSCRIPT" => $uriscriptfile, "DIRABSOLUTO" => $uriscriptexecution, "DIRLOGICO" => $uriexecutiondirectory, 
"INTERPRETE0" => $executionfile, "INTERPRETE" => $executionfile, "CONSULTA" => $consultas);
}
/* */
 
/* */
# simplifica parse de uri
function f_directorio_relativo ($urirequest, $uriscriptexecution) {
  @$urirequest = $urirequest."";
  @$uriscriptexecution = $uriscriptexecution."";
  if (strstr ($urirequest, "?")) {
    $execusiondate = substr (substr ($urirequest, 0, strpos ($urirequest, "?")), strlen ($uriscriptexecution));
    $consultas = substr ($urirequest, (strpos ($urirequest, "?") + 1));
  }
  else {
    $execusiondate = substr ($urirequest, strlen ($uriscriptexecution));
    $consultas = "";
  }
  return array ($execusiondate, $consultas) ;
}
/* */
 
/* */
function f_protocolos_web ($texto) {
  switch ($texto) {
    case "HTTP/1.1": $texto = "http"; break;
    default: $texto = ""; break;
  }
  return $texto;
}
/* */
 
/* */
function f_limpiardobles ($texto) {
  $texto = str_replace ("///", "/", $texto);
  $texto = str_replace ("//", "/", $texto);
  $texto = str_replace ("???", "?", $texto);
  $texto = str_replace ("??", "?", $texto);
  return $texto;
}
/* */
@ $segmentar_uri = f_segmentar_uri ();
$GLOBALS["URIFULL"] = $segmentar_uri["URIFULL"];
$GLOBALS["PROTOCOLO"] = $segmentar_uri["PROTOCOLO"];
$GLOBALS["EQUIPO"] = $segmentar_uri["EQUIPO"];
$GLOBALS["PUERTO"] = $segmentar_uri["PUERTO"];
$GLOBALS["PATHHTTPD"] = $segmentar_uri["PATHHTTPD"];
$GLOBALS["SISPATH"] = $segmentar_uri["SISPATH"];
$GLOBALS["WEBARCHIVO"] = $segmentar_uri["WEBARCHIVO"];
$GLOBALS["LOGICA"] = $segmentar_uri["URILOGICA"];
$GLOBALS["WEBLOGICO"] = $segmentar_uri["WEBLOGICO"];
$GLOBALS["REALDIR"] = $segmentar_uri["REALDIR"];
$GLOBALS["REALSCRIPT"] = $segmentar_uri["REALSCRIPT"];
$GLOBALS["DIRABSOLUTO"] = $segmentar_uri["DIRABSOLUTO"];
$GLOBALS["DIRLOGICO"] = $segmentar_uri["DIRLOGICO"];
$GLOBALS["INTERPRETE0"] = $segmentar_uri["INTERPRETE0"];
$GLOBALS["INTERPRETE"] = $segmentar_uri["INTERPRETE"];
$GLOBALS["CONSULTA"] = $segmentar_uri["CONSULTA"];
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.