Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code needed a clean-up first. There's a bunch of errors in it if you do a test run. It's also a bit hard to read IMO.</p> <p>I've attached a working code sample below.</p> <pre><code>// Get users $input_pwd = ( isset( $_POST["password"] ) ? $_POST["password"] : '' ); $input_user = ( isset( $_POST["username"] ) ? $_POST["username"] : '' ); // Your pseudo database here ;) $usernames = array( "username@domain1.com", "username2@domain1.com", "username3@domain1.com", "username1@domain2.com", "/[a-z][A-Z][0-9]@domain2\.com/", // use an emtpy password string for each of these "/[^@]+@domain3\.com/" // entries if they don't need to authenticate ); $passwords = array( "password1", "password2", "password3", "password4", "", "" ); // Create an array of username literals or patterns and corresponding redirection targets $targets = array( "username@domain1.com" =&gt; "http://www.google.com", "username2@domain1.com" =&gt; "http://www.yahoo.com", "username3@domain1.com" =&gt; "http://www.stackoverflow.com", "username1@domain2.com" =&gt; "http://www.serverfault.com", "/[a-z][A-Z][0-9]@domain2\.com/" =&gt; "http://target-for-aA1-usertypes.com", "/[^@]+@domain3\.com/" =&gt; "http://target-for-all-domain3-users.com", "/.+/" =&gt; "http://default-target-if-all-else-fails.com", ); $logindata = array_combine( $usernames, $passwords ); if ( get_user_data( $input_user, $logindata ) === $input_pwd ) { session_start(); $_SESSION["username"] = $input_user; header('Location: ' . get_user_data( $input_user, $targets ) ); exit; } else { // Supplied username is invalid, or the corresponding password doesn't match header('Location: login.php?login_error=1'); exit; } function get_user_data ( $user, array $data ) { $retrieved = null; foreach ( $data as $user_pattern =&gt; $value ) { if ( ( $user_pattern[0] == '/' and preg_match( $user_pattern, $user ) ) or ( $user_pattern[0] != '/' and $user_pattern === $user) ) { $retrieved = $value; break; } } return $retrieved; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload