From 310a1883d2392d70993a96bb14ceb4f0bd77c52e Mon Sep 17 00:00:00 2001 From: adrien Date: Tue, 6 May 2025 18:20:08 +0200 Subject: [PATCH] declare properties, use session without cookies --- 400.php | 2 +- classes.php | 21 +++++++++++++++------ index.php | 27 ++++++++++++++++----------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/400.php b/400.php index a95f404..cc56d3e 100755 --- a/400.php +++ b/400.php @@ -18,7 +18,7 @@ grille étant une suite de 81 caractères représentant la grille de gauche à droite puis de haut en bas, soit : Exemple :
diff --git a/classes.php b/classes.php index 8372a13..349a4d1 100755 --- a/classes.php +++ b/classes.php @@ -1,5 +1,5 @@ value = UNKNOWN; $this->rowId = $rowId; $this->columnId = $columnId; $this->regionId = $regionId; $this->candidates = $this->values; - $this->candidateRemoved = array(); - $this->neighbourhood = array(); } function searchCandidates() { @@ -48,8 +52,13 @@ } class Grid { + + private $boxes = array(); + private $rows; + private $columns; + private $regions; + function __construct($gridStr="") { - $this->boxes = array(); $this->rows = array_fill(0, 9, array()); $this->columns = array_fill(0, 9, array()); $this->regions = array_fill(0, 9, array()); diff --git a/index.php b/index.php index c68f106..191459a 100755 --- a/index.php +++ b/index.php @@ -1,19 +1,19 @@ false]); + + if (!array_key_exists("nbSolutions", $_SESSION)) { $grid = new Grid($currentGrid); - $sudokuGridSolutions[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2); + $_SESSION["nbSolutions"] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2); } - switch($sudokuGridSolutions[$currentGrid]) { + switch($_SESSION["nbSolutions"]) { case -1: $warning = "Cette grille contient des doublons."; break; @@ -27,13 +27,18 @@ } require("sudoku.php"); } else { - $grid = new Grid(); - $gridAsString = $grid->toString(); - $newGridUrl = "$dirUrl/?$gridAsString"; - $sudokuGridSolutions[$gridAsString] = 1; if ($currentGrid) { require("400.php"); } else { + $grid = new Grid(); + $gridAsString = $grid->toString(); + $newGridUrl = "$dirUrl/?$gridAsString"; + + session_id($gridAsString); + session_start(["use_cookies" => false]); + + $_SESSION["nbSolutions"] = 1; + header("Location: $newGridUrl"); } }