Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 27th, 2001, 04:19 PM
randor randor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Western New York
Posts: 85 randor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 9 m 46 sec
Reputation Power: 8
Send a message via Yahoo to randor
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

Reply With Quote
  #2  
Old April 27th, 2001, 06:34 PM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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};  
}

Reply With Quote
  #3  
Old April 29th, 2001, 10:08 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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.

Reply With Quote
  #4  
Old April 30th, 2001, 08:10 AM
Dave_L Dave_L is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 4 Dave_L User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 38 sec
Reputation Power: 0
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'.

Reply With Quote
  #5  
Old April 30th, 2001, 11:17 AM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #6  
Old April 30th, 2001, 12:00 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > getting the baseurl from the request?


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT