Hello

I'm not sure how this is possible but I want to enter a wildcard(?) into a php variable..

like this,

<?php
  if($_SERVER['HTTP_HOST'] == '*.domain.com') {
    //do something
  }
?>

Notice the *
I basically need it to match if its any subdomain of domain.com

Possible?

could use strlen and strpos to do that:

<?php
echo "strlen(\$_SERVER['HTTP_HOST']): ".strlen($_SERVER['HTTP_HOST'])."<br/>\r\n";
echo "strlen(\$_SERVER['HTTP_HOST']): ".strlen($_SERVER['HTTP_HOST'])."<br/>\r\n";
echo "strpos(\$_SERVER['HTTP_HOST'],'.domain.com'): ".strpos($_SERVER['HTTP_HOST'],'.domain.com')."<br/>\r\n";
echo "strlen(strpos(\$_SERVER['HTTP_HOST'],'.domain.com')): ".strlen('.domain.com')."<br/>\r\n";

if(strlen($_SERVER['HTTP_HOST']) == (strpos($_SERVER['HTTP_HOST'],'.domain.com') + strlen('.domain.com'))){
    echo "String ends: .domain.com<br/>\r\n";
}
?>

strpos might need +1 or -1 , it might miss a character off the count. Basically the first echoed number should equal the 2nd + 3rd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.