Bonjour
oui les sessions étaient bien démarré, je suis revenue en arrière dans le tuto j'avais loupé une étape.
Par contre maintenant je souhaite utiliser les jetons csrf donc j'ai mis ça sur ma page auth.php :
if(isset($_SESSION['csrf'])){
$_SESSION['csrf'] = md5(time() + rand());
}
function csrf(){
return 'csrf =' . $_SESSION['csrf'];
}
function checkCsrf(){
if(!isset($_GET['csrf']) || $_GET['csrf'] != $_SESSION['csrf']){
header('Location:' . WEBROOT . 'csrf.php');
die();
}
}
et ça sur mon category.php
<?php
include '../lib/includes.php';
include '../partials/admin_header.php';
$select = $db->query('SELECT id, name, slug FROM categories');
$categories = $select->fetchAll();
/**
*SUPPRESSION
**/
if(isset($_GET['delete'])){
checkCsrf();
}
?>
<h1>Les catégories</h1>
<table class="tablet table-striped">
<thead>
<tr>
<th>Id</th>
<th>Nom</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($categories as $category): ?>
<tr>
<td><?= $category['id']; ?></td>
<td><?= $category['name']; ?></td>
<td>
<a href="category_edit.php?id=<?= $category['id']; ?>" class="btn btn-default">Editer</a>
<a href="?delete=<?= $category['id']; ?>&<?= csrf(); ?>" class="btn btn-error" onclick="return confirm('Sur de sur ?');">Supprimer</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php include '../partials/footer.php'; ?>
lorsque je ne mets pas le <?= csrf(); ?> ligne 34, je n'ai pas d'erreur. Par contre dès que je rajoute ça, j'ai l'erreur suivante : Notice: Undefined index: csrf in C:\wamp64\www\portfolio\lib\auth.php on line 16...
Je ne comprends pas, avez vous une explication ?