본문 바로가기

[IT/Programming]/HTML related

Referer 알아내기 in Server (Vert.x) and Client (HTML/javascript)

728x90
반응형
# Referer 알아내기 in Server (Vert.x) and Client (HTML/javascript) Client (방문객) 이 어느 경로를 통해 들어왔는지, 어느 검색어를 통해 어느 검색엔진을 통해 들어왔는지 등을 알아내려면 어떻게 해야할까? Vert.x 랑 javascript 에서 쓰이는 referer/referrer 철자 (spelling) 가 다르네? ㅡㅂㅡ;;; ## PH
  • 2023-11-04 : Update window.kipid to window.m.
  • 2023-02-27 : First posting.
## TOC ## Referer in Vert.x server 참고 https://vertx.io/. ```[.linenums.lang-java] import io.vertx.core.AbstractVerticle; import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.Router; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class Recoeve extends AbstractVerticle { public static final String host="recoeve.net"; public static final String ENCODING="UTF-8"; public static final String INVALID_ACCESS="INVALID ACCESS"; private static long numberOfClients; static { numberOfClients=0; } @Override public void start() { Router router=Router.router(vertx); router.route().handler(ctx -> { HttpServerRequest req=ctx.request(); System.out.println("\n\nA client has connected!: "+(++numberOfClients)); final String referer=req.headers().get("Referer"); if (referer!=null) { try { System.out.println("Referer: "+URLDecoder.decode(referer, "UTF-8")); } catch (UnsupportedEncodingException e) { System.out.println(e); } } else { System.out.println("Referer: null"); } if (referer.substring(0,4).toLowerCase().equals("http")) { int k=4; if (referer.charAt(k)=='s'||referer.charAt(k)=='S') { k++; } if (referer.startsWith("://",k)) { k+=3; int l=referer.indexOf('/',k); String refererHost=null; if (l==-1) { refererHost=referer.substring(k); } else { refererHost=referer.substring(k,l); } System.out.println("Referer Host: "+refererHost); } } try { System.out.println("Absolute URI: "+URLDecoder.decode(req.absoluteURI(), "UTF-8")); } catch (UnsupportedEncodingException e) { System.out.println(e); } req.response().putHeader("Content-Type","text/plain; charset=utf-8"); req.response().end(INVALID_ACCESS, ENCODING); System.out.println(INVALID_ACCESS); }); vertx.createHttpServer() .requestHandler(router).listen(80); } // public void start() } // public class Recoeve extends AbstractVerticle ```/ ```[.linenums] // Log Example A client has connected!: 208 Referer: https://recoeve.net/CDN/docuK-2.3.css Referer Host: recoeve.net Absolute URI: https://recoeve.net/CDN/cc.png ```/ ## Document.referrer in HTML/Javascript 참고 MDN :: API - Document.referrer. ```[.linenums#pre-result] ```/ ```[.linenums.lang-html#pre-code-js] ```/ ## RRA
728x90
반응형