get('/profile', function(Silex\Application $app){ /** @var PDO $db */ $db = $app['db']; $id = $_GET['id']; $statement = $db->query("SELECT * FROM users WHERE id = $id"); $results = $statement->fetchAll(); $user = $results[0]; return <<
Username:
{$user['username']}
Email:
{$user['email']}
Full Name:
{$user['fullname']}
Bio:
{$user['bio']}
EOF; }); $app->get('/login', function(){ return << EOF; }); $app->post('/login', function(Silex\Application $app) { /** @var PDO $db */ $db = $app['db']; $username = $_POST['username']; $password = $_POST['password']; $statement = $db->query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); $results = $statement->fetchAll(); if(count($results) > 0) { return "Authenticated as " . $results[0]['username']; } else { return "Invalid username/password"; } }); $app->run();