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

like this,

  if($_SERVER['HTTP_HOST'] == '*.domain.com') {
    //do something

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


Recommended Answers

Answered by joshmac 0 in a post from

You may need to use domain matching to acheive your goal because I don't think it will work that way. Check out this post: http://stackoverflow.com/questions/4278564/regex-to-match-subdomains-other-than-www

Jump to Post

All 2 Replies

could use strlen and strpos to do that:

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, learning, and sharing knowledge.