Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2011, 12:19 AM   PM User | #1
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
wildcard a domain string

Hi

This works, but I would rather do something like in #2 example
PHP Code:
if ( $_SERVER['SERVER_NAME'] != ' www.domain.com' 
I'm trying to wildcard * everything in front of domain.com
PHP Code:
if ( $_SERVER['SERVER_NAME'] != ' * .domain.com' 
also if someone knows a better way to check a domain can
you please let me know?.

Thanks
Sonny

Last edited by sonny; 12-03-2011 at 03:16 AM..
sonny is offline   Reply With Quote
Old 12-03-2011, 01:42 AM   PM User | #2
Chris Hick
Regular Coder

 
Join Date: Oct 2010
Location: Florence, MS
Posts: 476
Thanks: 10
Thanked 33 Times in 32 Posts
Chris Hick is an unknown quantity at this point
are you trying to validate it with a specific domain name or just need to validate that it is a domain name?
__________________
Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
I always recommend the HEAD First series of books for learning a new coding language. ^_^
Chris Hick is offline   Reply With Quote
Old 12-03-2011, 01:54 AM   PM User | #3
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
Quote:
Originally Posted by Chris Hick View Post
are you trying to validate it with a specific domain name or just need to validate that it is a domain name?
With a specific domain name, and trying to wildcard anything in front of domain.com, like
Code:
www.domain.com
domain.com
http://domain.com
Sonny
sonny is offline   Reply With Quote
Old 12-03-2011, 02:45 AM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Not tested:
PHP Code:
if(preg_match('/.*somedomain\.com$/si'$_SERVER['SERVER_NAME']))
    echo 
'matched';
else
    echo 
'not matched'
You could also use strpos(), which would be faster, if you aren't concerned with the possibility of it being matched elsewhere in the string.
Inigoesdr is offline   Reply With Quote
Old 12-03-2011, 03:15 AM   PM User | #5
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
Thanks! Happy Holidays, I am marking solved (works)

but on a side note, do you think the performance issue of preg_match
outweighs the odds of someone just using htttp://domain.com?

Thanks again
Sonny
sonny is offline   Reply With Quote
Old 12-03-2011, 07:59 PM   PM User | #6
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by sonny View Post
but on a side note, do you think the performance issue of preg_match
outweighs the odds of someone just using htttp://domain.com?
Not sure what you mean there. The performance difference of using preg_match() isn't major, we are talking about milliseconds. Either way, it's up to you to decide which method is ideal for your purposes.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:14 AM.


Advertisement
Log in to turn off these ads.