Women in Technology

Hear us Roar



Article:
  Ten Security Checks for PHP, Part 1
Subject:   Nicer code
Date:   2003-03-24 13:42:28
From:   anonymous2
Hi guys,
I find this code better than yours:


$valid_pages = array ('apage.php',
'another.php',
'more.php');
if (!in_array($page, validpages)){
// Abort the script
// You should probably write a log message here too
die("Invalid request");
}


instead of:


$valid_pages = array(
"apage.php" => "",
"another.php" => "",
"more.php" => "");


if (!isset($valid_pages[$page])) {
// Abort the script
// You should probably write a log message here too
die("Invalid request");
}



Yours


Gustavo el Geranie

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Nicer code
    2009-01-23 20:03:51  NinjaTech [View]

    Your code may seem better, because it looks a bit cleaner, however his is quicker than yours, because it uses buckets and doesn't have to search the array to find every match.