0

hello I just wanted to check and see if this would be correct PHP syntax:

if ($input == "DeOnTRAY96@localhost"){
echo"
Projects: 1"?>
<br>
<?php     
echo"
Admin: yes
";

}
elseif ($input == NULL){
die("Please enter password.");
}else{
header("Location:Invalidpassword.php");
exit;
}

Right where is says

if($input == "DeOnTRAY96@localhost"){

Could I put

if($input == "DeOnTRAY96@localhost" or "somethingelse"){

And still have it work?

3 Answers3

0

You don't want

if($input == "DeOnTRAY96@localhost" or "somethingelse"){

You want

if($input == "DeOnTRAY96@localhost" or $input == "somethingelse"){

I might suggest using === instead of == in this case, as you'd like a type sensitive comparison.

Additionally, for $input == NULL you should use is_null($input). Null is weird in most programming languages, so language specific functions for testing are usually the way to go (rather than comparison)

preinheimer
  • 3,712
  • 20
  • 34
0

OR syntax in PHP:

if($var == 'something' || $var == 'something else')
{
  //do something
}

For reference:

|| means OR

&& means AND

psx
  • 4,040
  • 6
  • 30
  • 59
0

For a more future-proof solution, consider in_array. I use it for as few as two options, if there's even the slightest chance there may be more added.

if( in_array($input, ["DeOnTRAY96@localhost", "somethingelse"]))

Once you get to four or more options, it's probably better to do something more like:

$whitelist = [
      "DeOnTRAY96@localhost"
    , "somethingelse"
    , "anotheroption"
    , "too many options to do inline!"
];
if( in_array($input, $whitelist))
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592