Topic: Refering domain [SOLVED]

Im tring to figure out how to do this...

Right now i have this in my code:

def refer
 r = request.env["HTTP_REFERER"]
 rdomain = ???
 ** some other non important code here
end

the value of "r" gives me something like:
http://www.google.com/#sclient=psy& … b092c3cb09

However i want the value of "rdomain" to equal "google.com" without the tailing information. How exactly would i do this?

Thanks in advance

Last edited by Arcadie (2011-04-19 16:55:11)

Re: Refering domain [SOLVED]

Figured a way to do this...
Lets say you have this url for example:
http://www.anydomain.com/any?think=can&be=here
and you want to get just the referring domain of www.anydomain.com

here is how I did it

def find_refering_domain
  referring_url = request.env["HTTP_REFERER"]
  referring_domain = refering_url.gsub("http://", "").gsub("https://", "").gsub("www.", "").gsub("/", "#").gsub(/#.*$/, "")
end

Im sure there is a little more efficient way but this works.
It must go in this order and heres that it all does.

The first 2 gsubs turn this:
http://www.anydomain.com/any?think=can&be=here
into this:
www.anydomain.com/any?think=can&be=here

The third turns this:
www.anydomain.com/any?think=can&be=here
into this:
anydomain.com/any?think=can&be=here

The four turns this:
anydomain.com/any?think=can&be=here
into:
anydomain.com#any?think=can&be=here

and the last turns this:
anydomain.com#any?think=can&be=here
into this:
anydomain.com

The reason i turned "/" into "#" is because i could not find the code to gsub / + everything behind it, but i did find a way to do # plus everything behind that.