我想通过使用会话
来连接数据库中现有的用户<?php
//...
$app->match('/',function(Application $app, Request $req) {
$app['session']->set('login', $req->query->get('login'));
$app['session']->set('password', $req->query->get('password'));
$app['session']->set('login2', $req->query->get('login2'));
$app['session']->set('password2', $req->query->get('password2'));
// Je stocke les infos du fomulaire dans session.
$login=$app['session']->get('login');
$pass=$app['session']->get('password');
if ($app['db']->executeQuery('SELECT login FROM users WHERE login="'.$login.'"') == 1){
if($mdp = $app['db']->executeQuery('SELECT pass FROM users WHERE login="'.$login.'" AND pass="'.$pass.'"') == 1){
return $app->redirect('/signup'); // test
}
}
else {
return $app->redirect('/');
}
return $app['twig']->render('login.twig', array('users' => $result));
});
Twig代码:
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Créer un utilisateur</title>
<style>
p {
display:inline;
}
</style>
</head>
<body>
<h1>Connectez vous</h1>
<form method="post">
<p>Joueur1 </p><input type="text" name="login"
placeholder="choisissez un pseudo" required>
<p>Mot de passe </p><input type="password" name="password"
placeholder="choisissez un mot de passe" required>
<br>
<p>Joueur2 </p><input type="text" name="login2"
placeholder="choisissez un pseudo" required>
<p>Mot de passe </p><input type="password" name="password2"
placeholder="choisissez un mot de passe" required>
<br>
<input type="submit" value="connexion">
</form>
</body>
</html>
结果是它将我重定向到/注册而不让用户识别自己。