Skip to content

Instantly share code, notes, and snippets.

@GDmac
Created May 25, 2014 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GDmac/bc2dd40fc49dc4e3687f to your computer and use it in GitHub Desktop.
Save GDmac/bc2dd40fc49dc4e3687f to your computer and use it in GitHub Desktop.
Simple request
<?php
$req = parse_url($_SERVER['REQUEST_URI']);
// querystring
isset($req['query']) ? parse_str($req['query'], $req['query_arr']) : $req['query_arr'] = array();
// route
$req['route'] = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME']));
switch ($req['route']) {
case '/aa':
echo 'Hello ' . escape(trim($req['route'], '/'));
break;
default:
echo 'error';
break;
}
var_dump($req);
// =========================================================
function escape($text, $flags = ENT_COMPAT, $charset = null, $doubleEncode = true)
{
return htmlspecialchars($text, $flags, $charset ? $charset : 'utf-8', $doubleEncode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment