======== Projet_4/index.php =======
<?php
session_start();
include('./mvc/controller/main.php');
if(!empty($_POST['pseudo']) && !empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['rePassword'])){
$userAction = new ActionsUser();
$userAction->subscribeUser();
} elseif(!empty($_POST['pseudo']) && !empty($_POST['password'])){
$userAction = new ActionsUser();
$_SESSION['pseudoUser'] = $_POST['pseudo'];
$userAction->connectionUser();
}
if(isset($_POST['disconnectUser'])){
?><script>alert('Vous êtes déconnecté !')</script><?php
$disconnect = new ActionsUser();
$disconnect->disconnectUser();
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Bungee" rel="stylesheet">
<script crossorigin="anonymous" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="css/phoneFormat.css">
<link rel="stylesheet" href="css/tabFormat.css">
<link rel="stylesheet" href="css/desktopFormat.css">
<title>Blog du Writer</title>
</head>
<body>
<header>
<h1 id="titleBody">Le Wr!ter</h1>
<p>
<img src="img/writer.png" id="iconTitle" title="Contactez-nous !" alt="iconTitle">
</p>
</header>
<nav>
<ul id="menu">
<li class="li1"><a href="index.php">Accueil</a></li>
<li class="li2"><a href="#">Inscription</a></li>
<li class="li3"><a href="#">Livre d'or</a></li>
<li class="li4"><a href="#">Chat</a></li>
<li class="li5"><a href="#">Contact</a></li>
</ul>
</nav>
<?php
include('./mvc/view/slider.php');
displaySlider();
?>
<?php
include('./mvc/view/displayForm.php');
displayForm();
?>
</body>
</html>
======= Projet_4/mvc/model/checkForm.php ========
<?php
class CheckForm {
public function memberExistInscription(){
include('./mvc/model/databaseConnect.php');
if (!empty($_POST['pseudo']) && !empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['rePassword']) ) {
$pseudo = htmlspecialchars($_POST['pseudo']);
$email = htmlspecialchars($_POST['email']);
$req = $dbh->prepare("SELECT * FROM users
WHERE email= ? OR pseudo= ?
");
$req->execute(array($email, $pseudo));
$users = $req->fetch();
if($users['pseudo'] == $pseudo){
$this->errorSubscribeExistPseudo();
}elseif ($users['email'] == $email){
$this->errorSubscribeExistEmail();
}
elseif ($users['pseudo'] == null && $users['email'] == null){
$this->insertUser();
}
} else{
$this->errorUser();
}
}
public function memberExistConnection(){
include('./mvc/model/databaseConnect.php');
if (!empty($_POST['pseudo']) && !empty($_POST['password'])){
$pseudo = htmlspecialchars($_POST['pseudo']);
$passwordSalt = htmlspecialchars(hash("sha512" ,"azzjfa".$pseudo."15z1d"));
$password = htmlspecialchars(hash("sha256" , $_POST['password'].$passwordSalt));
$req = $dbh->prepare("SELECT * FROM users
WHERE pseudo= ?
");
$req->execute(array($pseudo));
$users = $req->fetch();
if($users['pseudo'] == $pseudo && $users['password'] == $password){
if(!isset($_COOKIE['pseudo'])){
$timerCookie = 60 ;
setcookie('pseudo', "a48f484fz" , $timerCookie);
}
$this->connectUser();
}elseif($pseudo == $users['pseudo'] && $users['password'] != $password){
$this->errorUserPassword();
}elseif ($users['pseudo'] == null){
$this->errorUser();
}
}
}
public function insertUser(){
include('./mvc/model/databaseConnect.php');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
$ip_address = $_SERVER['REMOTE_ADDR'];
}
if (!empty($_POST['pseudo']) && !empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['rePassword']) ){
$pseudo = htmlspecialchars($_POST['pseudo']);
$email = htmlspecialchars($_POST['email']);
$passwordSalt = hash("sha512" , "azzjfa".$pseudo."15z1d");
$password = hash("sha256" , $_POST['password'].$passwordSalt);
$req = $dbh->prepare("INSERT INTO users (pseudo , email , password, passwordSalt, ip)
VALUES (? , ? , ?, ?, ?)");
$req->execute(array($pseudo , $email , $password, $passwordSalt, $ip_address));
}
}
public function connectUser(){
header("Location:./?success=1");
exit();
}
public function disconnectUser(){
header("Location:./?disconnectUser=1");
exit();
}
public function errorUser(){
header("Location:./?error=1");
exit();
}
public function errorUserPassword(){
header("Location:./?errorPassword=1");
exit();
}
public function errorSubscribeExistPseudo(){
header("Location:./?errorSubscribeExistPseudo=1");
exit();
}
public function errorSubscribeExistEmail(){
header("Location:./?errorSubscribeExistEmail=1");
exit();
}
}
====== Projet_4/mvc/view/displayForm.php =====
<?php
function displayForm(){
echo '
<div id="containerForms">
<form action="./index.php" method="POST" id="formSubscribe">
<h3 id="titleSubscription">S\'inscrire</h3><br>
<div class="col">
<label for="inputText">Pseudo</label>
<input type="text" name="pseudo" class="form-control" placeholder="Pseudo" required>
</div><br>
<div class="col">
<label for="exampleFormControlInput1">E-mail</label>
<input type="email" name="email" class="form-control" id="exampleFormControlInput1" placeholder="nom@exemple.com">
</div><br>
<div class="col">
<label for="inputPassword4">Mot de passe</label>
<input type="password" name="password" class="form-control" id="inputPassword1" placeholder="Mot de passe" required>
</div><br>
<div class="col">
<label for="inputPassword4">Saisir à nouveau</label>
<input type="password" name="rePassword" class="form-control" id="inputPassword2" placeholder="Mot de passe" required>
</div><br>
<div class="col">
<button type="submit" class="btn btn-outline-success" id="submitSubscribe">Envoyer</button>
</div>
</form>
<form action="./index.php" id="formConnection" method="POST">
<h3 id="titleConnection">Se connecter</h3><br>
<div class="col">
<label for="exampleFormControlInput1">Pseudo</label>
<input type="text" name="pseudo" class="form-control" id="exampleFormControlInput2" placeholder="KevinDu12 ">
</div><br>
<div class="col">
<label for="inputPassword4">Mot de passe</label>
<input type="password" name="password" class="form-control" id="inputPassword3" placeholder="Mot de passe" required>
</div><br>
<div class="col">
<button type="submit" class="btn btn-outline-success">Envoyer</button>
</div>
</form>
</div>
';
}
?>
=========== Projet_4/mvc/model/error.php ============
<?php
if(isset($_GET['error'])){
echo '<script>alert("Erreur");</script>';
echo 'Error';
} elseif(isset($_GET['success'])){
include ('./mvc/view/redirectUser.php');
$userSpace = new RedirectUser();
$userSpace->checkAccessUser();
echo '<script>alert("Success");</script>';
echo 'Success';
} elseif(isset($_GET['errorPassword'])){
echo '<script>alert("Mauvais mot de passe");</script>';
echo 'Error Password';
} elseif(isset($_GET['errorSubscribeExistPseudo'])){
echo '<script>alert("Désolé ce Pseudo est déja pris.. :/");</script>';
echo 'Error Subscribe Exist Pseudo';
} elseif(isset($_GET['errorSubscribeExistEmail'])){
echo '<script>alert("Désolé cette Email est déja prise.. :/");</script>';
echo 'Error Subscribe Exist Email';
}
======= Projet_4/mvc/model/databaseConnect.php =====
<?php
$host_name = 'localhost';
$database = 'writer';
$user_name = 'root';
$password = '';
try {
$dbh = new PDO("mysql:host=$host_name; dbname=$database;", $user_name, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Erreur!: " . $e->getMessage() . "<br/>";
die();
}
============ Projet_4/mvc/controller/actionsUser.php
<?php
class ActionsUser {
public function receptForm(){
include('./mvc/model/checkForm.php');
}
public function subscribeUser(){
$this->receptForm();
$subscribeUser = new CheckForm();
$subscribeUser->memberExistInscription();
}
public function connectionUser(){
$this->receptForm();
$connect = new CheckForm();
$connect->memberExistConnection();
}
public function disconnectUser(){
$this->receptForm();
$disconnect = new CheckForm();
$disconnect->disconnectUser();
}
}
?>
===========我的问题========
一旦该项目在线托管后,我就没有定向到我想要的页面,我在GET中的请求不会出现在URL中,不会发出警报(),而本地无需担心..我的代码没有被注释,成为初学者没什么组织非常有条理,这对数据库在本地和在线工作都有危害。.注册和连接工作..我一点也不明白.. O__ *