Fix the dynamic content routing functions.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 10:00:14 +0000 (11:00 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 10:00:14 +0000 (11:00 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
index.php
login.php

index 01b3ce32fed45e398ceee1032a2c0798f187065f..2829b2676d9a720de486008b50984ba1f355fb97 100644 (file)
--- a/index.php
+++ b/index.php
@@ -14,6 +14,9 @@ $configs = include('config.php');
  */
 session_start();
 
+//$page = filter_input(INPUT_GET, $_GET['page'], FILTER_SANITIZE_URL);
+$page = $_GET['page'];
+
 if (!isset($page)) {
     $page = "";
 }
@@ -29,31 +32,34 @@ function valid_page($page_name)
     global $configs;
 
     foreach ($configs['actions'] as $action) {
-        if ($page_name === $action) {
-            return $action;
+        if (strcmp($page_name, $action) === 0) {
             // The actions list can't have duplicated entries
-            break;
-        } else {
-            return $configs['actions'][0];
+            return $action;
         }
     }
+    // Return the default action
+    return $configs['actions'][0];
 }
 
 function display_action($action_name)
 {
     global $configs;
 
+    $found_action = false;
     foreach ($configs['actions'] as $action) {
-        if ($action_name === $action) {
+        if (strcmp($action_name, $action) === 0) {
             include("$action.php");
+            $found_action = true;
             break;
-        } else {
-            echo "Action to display do not exist";
         }
     }
+    if (!$found_action) {
+        echo "Action to display do not exist";
+    }
 }
 
-display_action(valid_page($page));
+$action = valid_page($page);
+display_action($action);
 
 session_destroy();
 
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..89b3b2d468f972a37961dc32c1badba389c340f1 100644 (file)
--- a/login.php
+++ b/login.php
@@ -0,0 +1,5 @@
+<form action="action.php" method="post">
+ <p>Email : <input type="text" name="email" /></p>
+ <p>Mot de passe : <input type="text" name="password" /></p>
+ <p><input type="submit" value="OK"></p>
+</form>