I have a question in regards to $SERVER['SERVER_NAME'] or $SERVER[HOST']. I want to validate email addresses to try and prevent injection. According to this code, if the email address a malicious perso would try to inject is not of the same domain that the script is installed on, then it will give the message "Invalid Email Address".
I have come up with the following code:
<?php
$domref = $_SERVER['SERVER_NAME'];
$to = 'john@dough.com';
$host = $_SERVER['HTTP_HOST'];
list($user, $maildomain) = split("@", $to);
list($w, $domain) = split("www.", $domref);
if ( $domain == $maildomain ) {
$bob = 'Valid Email Address';
} else {
$bob = 'Email Address Invalid';
}
echo 'The email username is ' , "$username <br>";
echo "<br>";
echo 'The email domain is ' , "$maildomain <br>";
echo "<br>";
echo "This website is $domref or $domain <br>";
echo "<br>";
echo "The host is $host <br>";
echo "<br>";
echo "$bob";
?>
I already know that some of that code is kind of repeating itself as well as I need to write extra coding to fuly perform the rejection action that one would use in a form processing script. I only created some of the extra echo coding to see the differance between $SERVER['SERVER_NAME'] and $SERVER['HOST] as well as a way for me to see that the script is performing the functions I want it to do.
My question is that is there a way to get the host/domain of the website the script is on, but without the WWW part. I have tried both the SERVER_NAME and HOST. I still get www.mywebsite.com. The only workaround I can think of is to split the information as I have done in this script.
Thanks