Basic functions PHP

Ready file php with functions basic to add in its Web



<? php
  /* Obtiene the data passed through the URL *
  function segment ($segmento=0) \ {$segmentos = explode (€œ/€, $_SERVER [€˜HTTP_HOST€™] .str_replace (€œ.php€, "", $_SERVER [€˜PHP_SELF€™])); if (isset ($segmentos [$segmento]))\ {return $segmentos [$segmento]; } else \ {return $segmentos; }}

  /* Obtiene a data passed through $_POST surely *
  function post ($post=FALSE) \ {if (isset ($_POST [$post]))\ {$data = $_POST [$post]; } else \ {$data = $_POST; } if (is_array ($data))\ {foreach ($data ace $data_) \ {to $var_clear [] = htmlentities (trim ($data_), ENT_NOQUOTES); } return to $var_clear; } else \ {to $var_clear = htmlentities (trim ($data), ENT_NOQUOTES); return to $var_clear; }}

  /* Obtiene the data passed through the URL *
  function redirect ($uri = '') \ {if (! preg_match (€˜#^https: //#i€™, $uri))\ {#$uri = HTTP; } to header (€œRefresh: 0; url=€. $uri); exit; }
}



<! -- It gives back the first value passed through the URL -->
<? =segment (0)? >
<! -- It gives back all the values of the URL -->
<? =segment ()? >
<! -- It gives back the variable passed through clean $_POST of attacks to MySQL -->
<? =post (€˜name€™)? >
<! -- It redirects to the direction that we indicate -->
<? =redirect (€˜URL-it paginates-2€™)? >