title: PHP Regex String in Array
body: <p>I would like to be able to set a global username like <code>&lt;anythinghere&gt;@domain3.com</code> as a username value in the $usernames array (in code below). This is so that I can then go and redirect users based on domain, having already been "authenticated".</p>
  
  <p>I will put example in code below. </p>
  
  <p>Can i do something like <code>$usernames = array("username@domain1.com", $X)</code> where <code>$X = &lt;anything-so-long-as-not-blank&gt;@domain3.com</code>?</p>
  
  <p>Full Code Below:</p>
  
  <pre><code>&lt;?php
  
  //VALIDATE USERS
  $usernames = array("username@domain1.com", "username2@domain1.com", "username3@domain1.com", "username1@domain2.com", "username2@domain2.com", "username1@domain3.com");
  $passwords = array("password1", "password2", "password3", "password4", "password5", "password6");
  
  
  //REDIRECT SPECIFIC VALID USERS OR DOMAIN
  function get_page($username) {
  $username = strtolower($username);
  switch ($username) {
      case "username@domain1.com"    : return "http://www.google.com";
      case "username2@domain1.com"    : return "http://www.yahoo.com";
      case "username3@domain1.com"    : return "http://www.stackoverflow.com";
      case "username1@domain2.com"    : return "http://www.serverfault.com";
          }
  return preg_match('/@domain3\.com$/',$username) ?
  "http://www.backblaze.com" : "DefaultBackupPage.php";
  }
  $page = get_page($_POST['username']);
  
  for($i=0;$i&lt;count($usernames);$i++)
  
  {
    $logindata[$usernames[$i]]=$passwords[$i];
  }
  
  $found = 0; 
  
  for($i=0;$i&lt;count($usernames);$i++) 
  { 
     if ($usernames[$i] == $_POST["username"]) 
     { 
     $found = 1; 
     } 
  } 
  if ($found == 0) 
  { 
     header('Location: login.php?login_error=1'); 
     exit; 
  } 
  if($logindata[$_POST["username"]]==$_POST["password"])
  {
     session_start();
     $_SESSION["username"]=$_POST["username"];
     header('Location: '.$page);
     exit;
  }
  else
  {
     header('Location: login.php?login_error=1');
     exit;
  }
  ?&gt;
  </code></pre>
  
  <p>@inhan Has already helped me like a champ. I am wondering if any one can get me over the line? Cheers!</p>