Erlendftw

Sideverifisering i php

Oct 25th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2.    
  3.     /**
  4.      * [loadPage determines what page should be loaded]
  5.      * @return [string]
  6.      */
  7.     function loadPage()
  8.     {
  9.         global $_GET;
  10.  
  11.         //Verify that the data about the site actually exists.
  12.         if (!isset($_GET['side']))
  13.         {
  14.             return 'page_default';
  15.         }
  16.  
  17.         //I hate using get-variables, store in variable
  18.         $userSuppliedPage = $_GET['side'];
  19.  
  20.         //Verify that the page is allowed, do this by comparing it to an array with allowed pages.
  21.         $allowedPages = array('side1', 'side2', 'side3', 'side4');
  22.         if (!in_array($userSuppliedPage, $allowedPages))
  23.         {
  24.             //User tried to navigate to a webpage that ain't allowed, give 404-error.
  25.             return 'errors/404';
  26.         }
  27.  
  28.         //Verify that the page actually exists.
  29.         if (!file_exists('pagefiles/' . $userSuppliedPage . '.php'))
  30.         {
  31.             //File doens't exist. Give a 404-error.
  32.             return 'errors/404';
  33.         }
  34.  
  35.         //File exists and is valid. Security check is OK.
  36.         return $userSuppliedPage;
  37.  
  38.     }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment