|
|
|
|
|
|
|
![]() |
#1 |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Getting the Hostname in PHP
I've been searching all day, trying different functions, regular expressions, etc., but nothing I've tried seems to work fully,
![]() so I've decided to let someone else have a go... What I want to do is check for uniqueness of the domain of a submitted site. I do not even want to allow subdomains. So far I have this: PHP Code:
There is an example at php.net to get the hostname: PHP Code:
So it is over to the PHP gurus at ![]() There is no rush on this, but if I could have a solution by Thursday 12th Oct, that would be great ![]() Note - As you may have guessed, the '$url_in_db' is stored in a MySQL table, in case a function exists in a query expression that I may have missed.
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
![]() |
![]() |
![]() |
#2 |
Trying is the first step towards failure
|
Here's a really ugly way to do it... I'm sure there's a better one but this should work. Something like:
PHP Code:
![]()
__________________
Link List Land - Linklist Creation, Design and Implementation. |
![]() |
![]() |
![]() |
#3 |
Trying is the first step towards failure
|
I just realised that it might be easier for you to use regex after parse_url... Only just woken up, so the brain's only half fired up..
![]()
__________________
Link List Land - Linklist Creation, Design and Implementation. |
![]() |
![]() |
![]() |
#4 |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Thanks matt
I'll put the code to some in-house testing and let you know how I get on. Steve
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
![]() |
![]() |
![]() |
#5 |
Screw you, guys. I'm going home.
|
Try this - this function can be usefull for blacklist and recip checking as well
PHP Code:
http://mydomain.com/freesite1/freesite2/freesite3/ and http://mydomain.com/freesite1/ was already in DB I see no point in creating such directory structure for free sites and I guess nobody does Last edited by Mateusz; 2006-10-15 at 06:27 AM.. |
![]() |
![]() |
![]() |
#6 | |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Quote:
As far as I can see, your function will not do what I want it to. I.e. if [url]http://mydomain.com/freesite1/ was in the DB, if they then submitted http://www.mydomain.com/freesite1/, http://web.mydomain.com/freesite1/, http://sub.mydomain.com/freesite1/ and http://another.mydomain.com/freesite1/ it wouldn't catch them.
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
|
![]() |
![]() |
![]() |
#7 |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Matt, I just found a 'problem' with your code.
Let's say domain 'ThisWebsite.com' was listed. If, later, someone wanted to list 'EBSite.com' it would catch it as already listed... at least in my present MySQL query of "SELECT * FROM table WHERE url LIKE '%$url%'" or even "SELECT * FROM table WHERE url RLIKE '^http://([.a-z0-9]+)?$url'" I think I'm going to have to re-write the database, and add a 'domain' field for the extracted domain; and do an exact match on that. Oh well, at least there only 4,569 domains listed. ![]()
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
![]() |
![]() |
![]() |
#8 |
Screw you, guys. I'm going home.
|
Yeah, I must admit I misunderstood what exactly you are looking for.. The fact you are 'comparing' domain names only changes a lot.
Well, at least you could filter all of domains you have in database and and for the ones that have 1 dot (no subdomains and no .com.au like domains) in the host name run the script - #1 at http://pl.php.net/manual/pl/function.parse-url.php Maybe thats not much but I guess it would save you shitload of work anyway; rest would have to be done by hand... |
![]() |
![]() |
![]() |
#9 |
Trying is the first step towards failure
|
Yeah, you'll definately have to change the db if you're trying to search on it, but that will be really easy. Add a new field, SELECT all the urls, run the code on each of them and UPDATE.
![]()
__________________
Link List Land - Linklist Creation, Design and Implementation. |
![]() |
![]() |
![]() |
#10 | |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Quote:
Thanks for your input guys
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
|
![]() |
![]() |
![]() |
#11 |
Trying is the first step towards failure
|
Alternatively you could make sure www. exists for every url (add it yourself where it's not already there) and there's a trailing slash on all domains (so http://www.domain.com/ instead of http://www.domain.com), and search on ".EBSite.com/".
__________________
Link List Land - Linklist Creation, Design and Implementation. Last edited by matt; 2006-10-15 at 04:51 PM.. |
![]() |
![]() |
![]() |
#12 |
Heh Heh Heh! Lisa! Vampires are make believe, just like elves and gremlins and eskimos!
Join Date: Jan 2006
Posts: 72
|
Here's a function I use to get only the domain from a URL.. I think that's what you're after? Just pass it a url and it will return the domain.
Code:
function getdomain($url) { // patterns we need to match $pattern_hostname = '/^(http:\/\/)?([^\/]+)/i'; $pattern_domain = '/[^\.\/]+\.[^\.\/]+(\.[^\.\/]{2})?$/'; // extract hostname from URL string @preg_match($pattern_hostname, $url, $matches); $hostname = $matches[2]; // extract sld.tld(.cctld if exists) @preg_match($pattern_domain, $hostname, $matches); $domain = $matches[0]; return $domain; } Hope this helps.. QD Last edited by QuickDraw; 2006-10-18 at 02:55 AM.. |
![]() |
![]() |
![]() |
#13 |
Well you know boys, a nuclear reactor is a lot like women. You just have to read the manual and press the right button
|
You could check first if it's an IP, and if it's not, then do your stuff with the domain name.
__________________
My Asian Kitty - My Free Sites |
![]() |
![]() |
![]() |
#14 |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
QuickDraw, kitty_kate:
My submission rules do not permit IP address URLs, so that is not an issue. QuickDraw: Thanks for the function. Yes it appears do what I want it to... in that it gets the domain name... but it still has the issue I mentioned in post 7, where it matches similarly named, longer domains.
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
![]() |
![]() |
![]() |
#15 |
You can now put whatever you want in this space :)
|
Code:
function base_domain($url) { // parse out subdomains $url = parse_url($url); $host = $url['host']; $pattern = "/([\-a-z0-9]*\.)?([\-a-z0-9]*)\.([a-z0-9]*)/i"; preg_match($pattern, $host, $matches); $host = $matches[2] ."." .$matches[3]; return $host; }
__________________
Success is going from failure to failure without a loss of enthusiasm. Last edited by Halfdeck; 2006-10-18 at 09:08 AM.. |
![]() |
![]() |
![]() |
#16 |
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
|
Yes, Halfdeck. Also does the same as the others that have been mentioned. Thanks anyway.
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare. |
![]() |
![]() |
![]() |
|
|