Skip to content

Instantly share code, notes, and snippets.

@GDmac GDmac/hello.php
Created May 25, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.