1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
PHP_TP2/helloworld4.php

49 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2020-09-12 14:31:17 +02:00
<?php
$username = "";
if (isset($_POST["username"]))
$username = htmlspecialchars($_POST["username"]);
elseif ($_SESSION["p1905458"]) {
$username = $_SESSION["p1905458"];
if ( ini_get ( " session . use_cookies " ) ) {
$params = session_get_cookie_params();
setcookie(session_name(), "", -1, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
}
}
require("header.php");
?>
<form method="POST">
<label for="username">Username: </label>
<input id="username" name="username" value="<?= $username ?>" required>
<input type="submit">
</form>
<ul>
<?php
if ($username) {
$bdd = getPDO();
if ($bdd INSTANCEOF PDO)
try {
$req = $bdd->prepare("SELECT * FROM user WHERE username = ?");
$req->execute(array($username));
if (!$user = $req->fetch()) { ?>
<p><strong>No user found !</strong></p>
<a href="createUser.php"><button>Create a new user</button></a>
<?php } else {
for ($i = 0; $i < $user["nb"]; $i++) { ?>
<li>Hello <?= $user["word"] ?> !</li>
<?php }
}
$req->closeCursor();
} catch (Exception $e) {
databaseError($e);
}
elseif ($bdd INSTANCEOF Exception)
databaseError($bdd);
}
?>
</ul>
<?php require("footer.php") ?>