모바일에서 소셜 로그인을 하면 Cannot modify header information  오류가 뜹니다.

모바일에서 소셜 로그인을 하면 Cannot modify header information  오류가 뜹니다.

QA

모바일에서 소셜 로그인을 하면 Cannot modify header information  오류가 뜹니다.

본문

 

Warning: Cannot modify header information - headers already sent by (output started at /home/zzz/cccc/www/theme/custum01/tail.sub.php:26) in /home/zzz/cccc/www/plugin/social/Hybrid/Auth.php</b> on line 369

 

모바일에서 네이버나 카카오를 통해 로그인을 하려고 하면 이런 식으로 오류가 뜹면서 진행이 안됩니다.

pc에서는 멀쩡히 되는데 mobile에서만 이런 오류가 뜨네요.

 

검색해보니<?앞에 공백이 있으면 그런 오류가 생긴다 하는데 찾아봐도 공백도 없고 왜 안되는지 모르겠습니다.

아래는 오류가 발생하는 파일들인데 왜 모바일에서만 문제가 생기는지 제발 알려주세요ㅠ

 

 

tail.sub.php


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
 
?>
</body>
</html>
<?php echo html_end(); // HTML 마지막 처리 함수 : 반드시 넣어주시기 바랍니다. ?>

 

Auth.php


public static function redirect($url, $mode = "PHP") {
        if(!$mode){
            $mode = 'PHP';
        }
       
        Hybrid_Logger::info("Enter Hybrid_Auth::redirect( $url, $mode )");
 
        // Ensure session is saved before sending response, see https://github.com/symfony/symfony/pull/12341
        if ((PHP_VERSION_ID >= 50400 && PHP_SESSION_ACTIVE === session_status()) || (PHP_VERSION_ID < 50400 && isset($_SESSION) && session_id())) {
            session_write_close();
        }
 
       
        if ($mode == "PHP") { //ex)$url : http://xn--v52b19lba301k.kr/plugin/social/?hauth.start=Naver&hauth.time=1547706764
            //echo $url;exit;
            header("Location: $url");
        } elseif ($mode == "JS") {
            echo '<html>';
            echo '<head>';
            echo '<script type="text/javascript">';
            echo 'function redirect(){ window.top.location.href="' . $url . '"; }';
            echo '</script>';
            echo '</head>';
            echo '<body onload="redirect()">';
            echo 'Redirecting, please wait...';
            echo '</body>';
            echo '</html>';
        }
 
        die();
    }

이 질문에 댓글 쓰기 :

답변 1

다음과 같이 해볼 수 있을 것 같습니다.

 

tail.sub.php 수정


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
?>
</body>
</html>

 

tail.sub.php 파일에서 <?php 태그 이전에 공백이나 다른 출력이 없는지 확인해 보세요. 파일의 시작이 위와 같이 되어야 합니다:

 

Auth.php 파일 수정


public static function redirect($url, $mode = "PHP") {
    if (!$mode) {
        $mode = 'PHP';
    }
    Hybrid_Logger::info("Enter Hybrid_Auth::redirect( $url, $mode )");
    // Ensure session is saved before sending response
    if ((PHP_VERSION_ID >= 50400 && PHP_SESSION_ACTIVE === session_status()) || (PHP_VERSION_ID < 50400 && isset($_SESSION) && session_id())) {
        session_write_close();
    }
    ob_start(); // Start output buffering
    if ($mode == "PHP") {
        header("Location: $url");
    } elseif ($mode == "JS") {
        echo '<html>';
        echo '<head>';
        echo '<script type="text/javascript">';
        echo 'function redirect(){ window.top.location.href="' . $url . '"; }';
        echo '</script>';
        echo '</head>';
        echo '<body onload="redirect()">';
        echo 'Redirecting, please wait...';
        echo '</body>';
        echo '</html>

 

Auth.php 파일에서 헤더를 수정하는 부분을 보완해보세요. header 함수 호출 이전에 다른 내용이 출력되지 않도록 한 후에, 위와 같이 ob_start() 및 ob_end_flush()를 사용하여 출력을 버퍼링 하시면 되지 않을까 합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 276
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT