function render($twig, $sdata = array()) { $term = html_entity_decode($_GET['q']); $results = Application::searchUser($term); if (count($results) == 1) { // only one result, redirect to that player's page header("Location: /player/" . $results[0]['steamid']); } elseif (count($results) == 0 && preg_match('/[0-9]{17}/', $term)) { // no results, but query matches a steamid, try that header("Location: /player/" . $term); } else { // more than one result, render the search results page $data = array('results' => $results, 'query' => $_GET['q']); } echo $twig->render('search.php', array_merge($sdata, $data)); }