I am trying to redirect registered users who's email address contains a certain string.
example email 1 -> 12345@email.com
example email 2 -> 12345.abc@email.com
I want to separate emails containing .abc@email.com
and send them to a separate page using a header redirect. This is intended in signing in a user with an email containing .abc@
to an administration page.
Currently all users are being redirected to the same page regardless of the email address.
Example snippet code below. This is my first time asking a question, I hope I have supplied enough information.
$_SESSION["user_id"] = $row[0];
$_SESSION["fname"] = $row[1];
if ($email==".abc@email.com")
{
header('Location:home.php');
}
else
header ('Location:home2.php');
}
You need to cut off your email string, if you want to compare only the last part.
$cmp = ".abc@email.com";
if (substr($email, -strlen($cmp)) == $cmp)
{
header('Location:home.php');
}
else
header ('Location:home2.php');
}
You should work with regular expression. (http://php.net/manual/en/function.preg-match.php)
Try do it:
preg_match("/\.abc@email\.com$/", $email, $result);
if (!count($result))
{
// Go to .abc@ page
header('Location:home.php');
} else
header ('Location:home2.php');
saluti,