include 'utils.php'; session_start(); $username = $_SESSION["username"]; if (!isset($username) || $username == "") { http_response_code(403); echo "{$username} is not connected. Press connect.\n"; echo "Maybe something went wrong with the session, I don't know. Refresh browser 3 times.\n"; } opendb(); $user = get_user($username); if (!$user) { http_response_code(403); echo "{$username} is not connected. Press connect.\n"; echo "Maybe you've timed out my friend. Refresh browser 5 times\n"; } touch_user($username); cleanup(); $d = opendir(constant('BASEPATH') . $username); $files = array(); while (false !== ($entry = readdir($d))) { if (preg_match("/^\\./", $entry)) { continue; } if (preg_match("/^__/", $entry)) { continue; } array_push($files, $entry); } asort($files); if (count($files) >= 1) { $file = constant('BASEPATH') . $username . '/' . $files[0];
function add_user($username) { if (get_user($username)) { echo "found {$username}\n"; touch_user($username); return; } if (!is_dir(constant("BASEPATH") . $username)) { if (!mkdir(constant("BASEPATH") . $username)) { http_response_code("500"); echo "failed to create user\n"; } } global $dbh; $again = true; while ($again) { $again = false; try { $getUsers = $dbh->prepare("INSERT INTO users (name,last) VALUES(:name,:last)"); $getUsers->bindValue(":name", $username, SQLITE3_TEXT); $getUsers->bindValue(":last", time(), SQLITE3_INTEGER); $getUsers->execute(); } catch (Exception $e) { // do the unthinkable $again = true; } } }