[게시판] [javascript/php] 뒤로가기 히스토리 체크 referer - 목록 버튼의 링크를 뒤로가기로 해야할까 a href로 해야할까. 5
2022.01.21 03:17
906
0
https://eond.com/443669
object(HotopayModel)#817 (23) { ["error"]=> int(0) ["message"]=> string(7) "success" ["variables"]=> array(0) { } ["httpStatusCode"]=> int(200) ["module"]=> string(7) "hotopay" ["module_info"]=> NULL ["origin_module_info"]=> NULL ["module_config"]=> NULL ["module_path"]=> string(52) "/home/eond/web/eond.com/public_html/modules/hotopay/" ["xml_info"]=> NULL ["module_srl"]=> NULL ["mid"]=> NULL ["act"]=> NULL ["template_path"]=> NULL ["template_file"]=> NULL ["layout_path"]=> NULL ["layout_file"]=> NULL ["edited_layout_file"]=> NULL ["stop_proc"]=> bool(false) ["user"]=> object(Rhymix\Framework\Helpers\SessionHelper)#816 (20) { ["member_srl"]=> int(0) ["user_id"]=> NULL ["user_name"]=> NULL ["nick_name"]=> NULL ["email_address"]=> NULL ["phone_number"]=> NULL ["homepage"]=> NULL ["blog"]=> NULL ["birthday"]=> NULL ["denied"]=> NULL ["status"]=> NULL ["is_admin"]=> string(1) "N" ["is_site_admin"]=> NULL ["profile_image"]=> NULL ["image_name"]=> NULL ["image_mark"]=> NULL ["signature"]=> NULL ["description"]=> NULL ["group_list"]=> array(0) { } ["menu_list"]=> array(0) { } } ["request"]=> object(Rhymix\Framework\Request)#10 (13) { ["method"]=> string(3) "GET" ["compat_method"]=> string(3) "GET" ["url"]=> string(21) "xe/443669/page/465443" ["hostname"]=> string(8) "eond.com" ["domain"]=> NULL ["protocol"]=> string(5) "https" ["callback_function"]=> string(0) "" ["_route_status":protected]=> int(200) ["_route_options":protected]=> object(stdClass)#11 (5) { ["cache_control"]=> bool(true) ["check_csrf"]=> bool(true) ["is_forwarded"]=> bool(false) ["is_indexable"]=> bool(true) ["enable_session"]=> bool(true) } ["module"]=> string(5) "board" ["mid"]=> string(2) "xe" ["act"]=> string(16) "dispBoardContent" ["args"]=> array(4) { ["document_srl"]=> string(6) "443669" ["page"]=> int(1) ["mid"]=> string(2) "xe" ["act"]=> string(16) "dispBoardContent" } } ["ajaxRequestMethod"]=> array(2) { [0]=> string(6) "XMLRPC" [1]=> string(4) "JSON" } ["gzhandler_enable"]=> bool(true) }

1. 문제인식

게시판 글보기의 링크를 {getUrl()}로 처음엔 했었다.

그런데 글을 보았다가 다시 목록 페이지로 돌아가기 위해 목록버튼을 클릭할 때마다,

스크롤을 내렸을 때 화면이 아닌 목록 첫 맨 위의 화면부터 뜨는 것이었다.


그래서 버튼 링크를 history.back 로 바꾸었다.


그런데 문제가 있었다. 만약 그 페이지가 새 창에서 떴다면?

돌아갈 히스토리 페이지가 없었다.


답은 이거였다.

document.referrer


1) 만약 관리자 페이지에서였다면

2) 새창이었다면

3) 최종. 그럼 리퍼러가 bbs일 경우에만 뒤로가기로 동작하고 그게 아니라면 목록 페이지로 돌아가게 만들어야 한다.


<!--@if($_SERVER['HTTP_REFERER']==getenv('HTTP_REFERER'))-->
<a href="javascript:history.back();" class="btn list">목록 보기</a>
<!--@else-->
<a href="{getUrl('document_srl','')}" class="btn list">목록 보기</a>
<!--@end-->


참조

https://xe1.xpressengine.com/qna/22904454

http://chongmoa.com/xe/2571


https://xetown.com/questions/1407780


1. javascript 뒤로가기 히스토리가 없는 것을 어떻게 확인할 수 있을까?

https://programmingsummaries.tistory.com/318

2. [javascript] 사용자가 브라우저 기록으로 돌아갈 수 있는지 확인하는 방법

http://daplus.net/javascript-%EC%82%AC%EC%9A%A9%EC%9E%90%EA%B0%80-%EB%B8%8C%EB%9D%BC%EC%9A%B0%EC%A0%80-%EA%B8%B0%EB%A1%9D%EC%9C%BC%EB%A1%9C-%EB%8F%8C%EC%95%84%EA%B0%88-%EC%88%98-%EC%9E%88%EB%8A%94%EC%A7%80-%ED%99%95/

3. PHP : REFERER 이전페이지를 이용한 보안

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=psj9102&logNo=220925199042


#2022년 1월 30일 업데이트

https://www.php.net/manual/en/function.parse-url.php

<!--@if(explode("/",parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH))[1]==$mid)-->
<a href="javascript:history.back();" class="btn list">목록 보기</a>
<!--@else-->
<a href="{getUrl('document_srl','')}" class="btn list">목록 보기</a>
<!--@end-->

parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH 이용했습니다.

PHP의 parse_url 함수에는 path까지 출력해주는 옵션이 있었군요!!

라이믹스는 이온디와 함께

  • 2022.01.30 13:44
    베스트
    <!--@if($_SERVER['HTTP_REFERER']==getenv('HTTP_REFERER'))-->
    <a href="javascript:history.back();" class="btn list">목록 보기</a>
    <!--@else-->
    <a href="{getUrl('document_srl','')}" class="btn list">목록 보기</a>
    <!--@end-->

    이렇게 하니깐 문제가 있네요.

    글 수정시에도 저게 같이 되서.. 이전 페이지에서 mid 까지 같은지 체크하는 방법을 다시 연구해야겠습니다.

  • 2022.01.30 14:08
    베스트
    1<pre>{var_dump(parse_url($_SERVER['HTTP_REFERER']))}</pre> <br>
    2<pre>{parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH)}</pre> <br>
    3{$_SERVER['HTTP_REFERER']} <br>
    4{$_SERVER['HTTP_HOST']} <br>
    5{$referer['host']} <br>
    
    6{$_SERVER['HTTP_REFERER']} <br>
    7{getenv('HTTP_REFERER')}

    2번을 explode 해서...

  • 2022.01.30 14:09
    베스트
    {var_dump(explode("/",parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH))[1])}

    위 값이랑 $mid 값이랑 같으면 뒤로가기, 다르면 $mid로 링크 걸어주기로 함.

  • 2022.01.30 14:12
    베스트
    <!--@if(explode("/",parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH))[1]==$mid)-->
    <a href="javascript:history.back();" class="btn list">목록 보기</a>
    <!--@else-->
    <a href="{getUrl('document_srl','')}" class="btn list">목록 보기</a>
    <!--@end-->

    현재 수정된 방법은 위와 같습니다.

  • 2022.02.03 08:28
    베스트
    <!--@if(getenv('HTTP_REFERER')==getUrl().Context::get('mid'))-->

    이건 뭔지 나중에 다시 확인하기..

닫기

마이페이지

로그인을 해주세요

네이버로 로그인