|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hello,
can anyone tell me what env. variable i use to get JUST the domain name from the place that the request came from, for instance: if someone comes to my script from www.yourdomain.com/inhere/fromhere.htm - i want to just retrieve the www.yourdomain.com thank you for any help. Randor |
|
#2
|
||||
|
||||
|
Hi!
I'd recommend using $ENV{HTTP_HOST}. It even gives you the expected output if you are on a name based virtual host. Not so with $ENV{SERVER_NAME}, it holds only the server's main name. Greetings Atrus. P.S.: (I just added this) You might not get the 'www.' in front, depending on your provider's setup. You can easily add it by checking if it's there and prepending it if not: Code:
my $serverstring ='';
unless ( $ENV{HTTP_HOST} =~ /^www\./ ) {
$serverstring = 'www.'.$ENV{HTTP_HOST};
}
|
|
#3
|
|||
|
|||
|
I had exactly what you wanted typed in, but vbb's stupid flood protection along with vbb's non-caching headers F(ucked) it, so never mind (I'm not retyping it). Blame the server admin for enabling flood protection.
|
|
#4
|
|||
|
|||
|
Prepending the 'www' if it's not there would not be a good idea if the URL could be a subdomain. E.g., 'whatever.example.com' would be changed to 'www.whatever.example.com'.
|
|
#5
|
||||
|
||||
|
Hi!
Dave_L is right, prepending things that are not there is potentially dangerous. And after all it is not necessary since the browser obviously found your page with only the current value of the host header, so no tweaking necessary. I just included this in my first post since on my websites the possible values for http_host are very limited and there always are matching www subdomains configured in apache. I just use the concatenated string for beautifying the website, the initial value is (as pointed out above) good enough (and used unchanged) for code and links though..... Greetings Atrus. |
|
#6
|
|||
|
|||
|
Heh, fine, i'll answer with that I had say.
Code:
if($ENV{HTTP_REFERER}) {
if($$ENV{HTTP_REFERER} =~ m|(https?://)([^/]+)/|) {
$referrer = $2;
} else {
if($ENV{HTTP_REFERER} =~ m|(https?://)(.+?)|) {
$referrer = $2;
} else {
# Something isn't right with the format of the referer in this case
}
}
}
This is totally untested code, but should work. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > getting the baseurl from the request? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|