Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:35:49+00:00 2026-06-13T11:35:49+00:00

I have some hardcoded if/else statements to set $page variable – (for later use

  • 0

I have some hardcoded if/else statements to set $page variable – (for later use in header: “.page”) – to a given website based on the $_POST[“username”] input.

CODE:

if ($_POST["username"] == "username1@domain1.com") {
$page = "http://www.google.com";
}
 else if ($_POST["username"] == "username2@domain1.com"){
$page = "http://www.yahoo.com";
}
 else if ($_POST["username"] == "username1@domain2.com"){
$page = "http://www.stackoverflow.com";
}
 else if ($_POST["username"] == "username2@domain2.com"){
$page = "http://www.serverfault.com";
}
 else if ($_POST["username"] == "username@domain3.com"){
$page = "http://www.superuser.com";
}
 else if (!preg_match($domain2.com, $_POST["username"]))  { //THIS IS VERY WRONG
$page = "http://www.backblaze.com";
}
else{
$page = "DefaultBackupPage.php";
}

I am trying to say if your username has “@domain.com” at the end of it, set the $page to, in this case backblaze.com, but could be anything.

I am aware it is messy, I don’t actually like this implementation. It just has to fit in this schema and I need a quick fix!

The current error I am receiving is that the regular expression is empty. I am hoping this is a no brainer for someone who knows PHP – which I have been hastily trying to learn!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:35:50+00:00Added an answer on June 13, 2026 at 11:35 am
    if (preg_match('/@domain2\.com$/i',$_POST['username']))
    

    will catch username ending with domain2.com. Please note the escaping backward slash for the dot. If you want to test against the opposite (aka. does NOT end with domain2.com) then use an exclamation mark before the preg_match() function.

    Is this what you were asking?

    EDIT 1: I added the i flag to the pattern to make it look for a case-insensitive match.

    EDIT 2: For the sake of readability and control I would wrap this in a function instead, but that’s my own preference so it’s not the suggested approach or anything. In case your code is long and complicated…

    function get_page($username) {
        $username = strtolower($username);
        switch ($username) {
            case "username1@domain1.com"    : return "http://www.google.com";
            case "username2@domain1.com"    : return "http://www.yahoo.com";
            case "username1@domain2.com"    : return "http://www.stackoverflow.com";
            case "username2@domain2.com"    : return "http://www.serverfault.com";
            case "username@domain3.com"     : return "http://www.superuser.com";
        }
        return preg_match('/@domain2\.com$/',$username) ?
        "http://www.backblaze.com" : "DefaultBackupPage.php";
    }
    
    $page = get_page($_POST['username']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Scrapy project that I want to use to scrape some websites.
I have drawn shape on html5 canvas with some hardcoded pixels. now I want
I have currently hard-coded in some data for a demo of a project. The
I have some data loaded as a np.ndarray and need to convert it to
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some tables roughly like so: Client: id name Employee id name Email
I have some table: Title 1 | Title 2 | Title 3 | --------------------------------------------------
I have some code that will change the background color of a specific label

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.