declare properties, use session without cookies
This commit is contained in:
parent
4b92464c94
commit
310a1883d2
2
400.php
2
400.php
@ -18,7 +18,7 @@
|
||||
<em>grille</em> étant une suite de 81 caractères représentant la grille de gauche à droite puis de haut en bas, soit :
|
||||
<ul>
|
||||
<li>un chiffre entre 1 et 9 pour les cases connues</li>
|
||||
<li>un point pour les case vides</li>
|
||||
<li>un tiret (-) pour les case vides</li>
|
||||
</ul>
|
||||
Exemple :<br/>
|
||||
<a href='<?=$newGridUrl?>'><?=$newGridUrl?></a>
|
||||
|
21
classes.php
21
classes.php
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
const UNKNOWN = ".";
|
||||
const UNKNOWN = "-";
|
||||
|
||||
$validGrids = array();
|
||||
|
||||
@ -27,15 +27,19 @@
|
||||
|
||||
class Box {
|
||||
public $values = array('1', '2', '3', '4', '5', '6', '7', '8', '9');
|
||||
|
||||
public $value = UNKNOWN;
|
||||
public $rowId;
|
||||
public $columnId;
|
||||
public $regionId;
|
||||
public $candidates;
|
||||
public $candidateRemoved = array();
|
||||
public $neighbourhood = array();
|
||||
|
||||
function __construct($rowId, $columnId, $regionId) {
|
||||
$this->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());
|
||||
|
27
index.php
27
index.php
@ -1,19 +1,19 @@
|
||||
<?php
|
||||
require("classes.php");
|
||||
|
||||
global $sudokuGridSolutions;
|
||||
if (!isset($sudokuGridSolutions)) $sudokuGridSolutions = array();
|
||||
|
||||
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
|
||||
$dirUrl = dirname($fullUrl);
|
||||
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
|
||||
|
||||
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
|
||||
if (!array_key_exists($currentGrid, $sudokuGridSolutions)) {
|
||||
if (preg_match("/^[1-9-]{81}$/", $currentGrid)) {
|
||||
session_id($currentGrid);
|
||||
session_start(["use_cookies" => 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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user