Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 2006-10-13, 10:03 AM   #1
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
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:
$url_in_db 'http://www.domain.tld/thispage.html';
$submitted_url 'http://www.domain.tld/anotherpage.html';

$parsedurl parse_url($submitted_url);
$get_the_hostname $parsedurl["host"];

if (
strstr ($url_in_db$get_the_hostname))
echo 
"match found";
else
echo 
"no match"
That works, but it doesn't do exactly what I want it to do, because although it finds a match if the 'www.' is left off, it doesn't find a match on a subdomain entry like 'http://web.domain.tld/thispage.html'

There is an example at php.net to get the hostname:
PHP Code:
preg_match('@^(?:http://)?([^/]+)@i'"http://www.domain.tld/index.html"$matches);
$host $matches[1];
preg_match('/[^.]+\.[^.]+$/'$host$matches); 
This doesn't work for the '.co.uk', '.com.au', etc TLDs as it returns the last two elements of the domain, nor would it match any 'https://' URLs

So it is over to the PHP gurus at & |Jim

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.
oast is offline   Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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 -4. The time now is 02:58 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc