개발 Q&A

제목 CI측 post수신 토큰,베이직인증
카테고리 PHP
글쓴이 포카포카 작성시각 2018/01/27 17:37:11
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 12673   RSS

포스트수신측 서버가 CI가 아닌서버에서는 문제없이 수신이 됩니다만

CI서버로 포스트송신을 보내면 에러가 돌아옵니다.

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

HTTP/1.1 401 Unauthorized Date: Sat, 27 Jan 2018 08:59:46 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 WWW-Authenticate: Basic realm="Please enter Username and Password" Content-Length: 381 Content-Type: text/html; charset=iso-8859-1 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive

에러내용보면 베이직인증 유저 아이디 하고 패스워드를 넣으라고 하는데

curl_setopt($ch, CURLOPT_USERPWD, "aaaaa:xxxxx"); 이걸 넣었는데 말입니다..

그래서 베이직 인증을 ` $headers`에 추가 하면

"Authorization: Basic ".base64_encode("aaaa:bbbb")

다음과 같은 에러가 나옵니다.

HTTP/1.1 403 Forbidden Date: Sat, 27 Jan 2018 09:01:58 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Content-Length: 1191 Content-Type: text/html; charset=UTF-8 Set-Cookie: csrf_cookie_name=34179d3bdd32270ae8897a3324c8ea2f; expires=Sat, 27-Jan-2018 11:01:58 GMT; path=/ Keep-Alive: timeout=5, max=100 Connection: Keep-Alive

An Error Was Encountered

The action you have requested is not allowed.

 

$config['csrf_protection'] = TRUE;이걸 false로 바꾸지 않고 해결할수 있는 방법이 있을까요

3일 째 헤매고 있습니다.

도와주세요

 

###################################################################

postsend.php내용

    $headers = array(

        "HTTP/1.0",

        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",

        "Accept-Encoding:gzip ,deflate",

        "Accept-Language:ja,en-us;q=0.7,en;q=0.3",

        "Connection:keep-alive",

        "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0",

        "Content-Type: text/plain" ,

       , "Authorization: Basic ".base64_encode("aaaa:bbbb")

        "Authorization: csrf_test_name e7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // 

    );

        $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $_url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch,CURLOPT_POST, true);

        // basic인증

    // curl_setopt($ch, CURLOPT_USERPWD, "aaaaa:xxxxx");

    curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);

      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($ch, CURLOPT_HEADER, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));

 

    $response = curl_exec($ch);

 

CI $config.php

$config['csrf_protection'] = TRUE;

$config['csrf_token_name'] = 'csrf_test_name';

$config['csrf_cookie_name'] = 'csrf_cookie_name';

$config['csrf_expire'] = 7200;

$config['csrf_regenerate'] = FALSE;

$config['csrf_exclude_uris'] = array('api/v1/sessions','api/v1/attendances','api/v1/session_applications','api/v1/exhibition_entries');

 다음글 테이블 헤더 고정 목록 스크롤 (1)
 이전글 PHPMailer 와 php7 질문입니다. (1)

댓글

변종원(웅파) / 2018/01/28 23:25:42 / 추천 0

매뉴얼에서 csrf 부분 참고해서 해당 값을 추가해서 보내시면 됩니다.

http://www.ciboard.co.kr/user_guide/kr/libraries/security.html#cross-site-request-forgery-csrf

포카포카 / 2018/02/03 18:46:59 / 추천 0

웅파 님 

답변 감사합니다. 정말 감사합니다.

결론을 먼저 말씀드리면,  계속 에러 입니다.

제가 내린 결론은 post수신서버가 베이직 인증 뒤에  CI가 csrf protection = true의 경우는 curl전송은 어림도 없다 입니다.

해외 찾아봐도 이런 경우 질문조차 없고. 베이직 인증 또는 토큰첨부로 푸는법이 있어서 질문에도써넣었습니다만.

둘다 넣을경우 하나만 인식해서 에러가 발생하는것이

쉽게 풀릴것 같으면서도 안풀리네요. 일단 다른 일반 서버로 수신확인했기에 그냥 진행하는걸로 끝이 났습니다.

기분나쁘지만 현재로는 방법이 없네요.