![]() |
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, |banghead|
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 |greenguy| & |Jim There is no rush on this, but if I could have a solution by Thursday 12th Oct, that would be great :D 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. |
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:
|
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.. :) But it would still be pretty much doing with i did in php with regex... Depends how neat you like your code!
|
Thanks matt
I'll put the code to some in-house testing and let you know how I get on. Steve |
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 |
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. |
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. :( |
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... |
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. :)
|
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/".
|
Quote:
Thanks for your input guys |
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) Hope this helps.. QD |
You could check first if it's an IP, and if it's not, then do your stuff with the domain name.
|
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.
|
Code:
function base_domain($url) { // parse out subdomains |
Quote:
|
All times are GMT -4. The time now is 03:10 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc