Skip to content

Instantly share code, notes, and snippets.

@henkm
Created March 2, 2011 14:35
Show Gist options
  • Save henkm/851026 to your computer and use it in GitHub Desktop.
Save henkm/851026 to your computer and use it in GitHub Desktop.
def get_referal
# controleren of er een ref-param is (mijndagjeweg.nl?ref=ze.nl)
# wordt gebruikt bij aanmelden nieuwe User
if params[:ref]
cookies[:ref] = params[:ref]
end
if request.remote_ip == "66.249.66.148"
logger.debug "Google BOt"
# redirect_to "http://www.teamtrips.nl/"
end
robots = ["Baiduspider+(+http://www.baidu.com/search/spider.htm)", "Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)", 'baidu','Googlebot','66.249.66.68', '66.249.66.52', '204.236.235.245', 'Mediapartners-Google', 'msnbot','Yahoo! Slurp China','bot','mnogosearch','crawl','slurp','spider','spyder','yandex','data','content','creep','scooter','internet','tricus','search','download','check','ingrid','adsense','magpie','arks','askjeeves','turn it in','shinchakubin','alexa','appie','rambler','marvin','voila','netcraft','larbin','voyager','pompos','linkchecker','orlando','big brother','echo','mirago','linkwalker','digger','archiver','robi','patric','holmes','jemmathetourist','index','wise-guys','ilse','curl','teoma','ask','jeeves','yanga','ichiro','sargas','ndex', 'Slurp']
# unless request.referer.to_s.include? "www.dagjewegawakrd" or robots.include? request.remote_ip.to_s or robots.any? {|str| request.env['HTTP_USER_AGENT'].include? str}
unless request.referer.to_s.include? "www.mijndagjeweg.nl" or session[:visited]
@referal = Referal.new
@referal.url = request.env['HTTP_REFERER']
@referal.ip = request.remote_ip
begin
if request.referer.to_s.include? "search?q="
@referal.query = request.referer.to_s #.split('search?q=').last.split('&').first.gsub('+', ' ')
else
@referal.query = request.referer.to_s #.split('&q=').last.split('&').first.gsub('+', ' ')
end
rescue StandardError => e
puts "Kon referer niet splitten: #{e}"
end
forbidden = ["213.93.71.181","80.61.222.210","80.56.12.241","77.249.59.54","83.98.206.215"]
unless forbidden.include? request.remote_ip.to_s or @referal.url.nil?
session[:visited] = true
@referal.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment