테스트 사이트 - 개발 중인 베타 버전입니다

goto_url($url) 보안 규정 준수 채택완료

울라프 5개월 전 조회 1,288

</strong>

 </p>

<p><strong>// 메타태그를 이용한 URL 이동

// header("location:URL") 을 대체

function goto_url($url)

{

    run_event('goto_url', $url);</strong></p>

<p><strong>    if (function_exists('safe_filter_url_host')) {

        $url = safe_filter_url_host($url);

    }</strong></p>

<p><strong>    $url = str_replace("&", "&", $url);

    //echo "<script> location.replace('$url'); </script>";</strong></p>

<p><strong>    if (!headers_sent())

        header('Location: '.$url);

    else {

        echo '<script>';

        echo 'location.replace("'.$url.'");';

        echo '</script>';

        echo '<noscript>';

        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';

        echo '</noscript>';

    }

    exit;

}</strong></p>

<p>

<strong>

 

위의 코드가 에러가 나서 아래와 같이 바꿔주니 에러 없이 잘 작동합니다. Warning: Header may not contain more than a single header, new line detected in

갑자기 왜 에러가 났죠?  크롬 보안이나 php 보안 규정이 강화 되었나요?

 

</strong>

 </p>

<p><strong>function goto_url($url)

{

    run_event('goto_url', $url);</strong></p>

<p><strong>    if (function_exists('safe_filter_url_host')) {

        $url = safe_filter_url_host($url);

    }</strong></p>

<p><strong>    // 줄바꿈 문자 제거

    $url = str_replace(["\r", "\n", '%0A', '%0D'], '', $url);

    $url = str_replace("&", "&", $url);</strong></p>

<p><strong>    if (!headers_sent()) {

        header('Location: '.$url);

    } else {

        echo '<script>';

        echo 'location.replace("'.htmlspecialchars($url, ENT_QUOTES).'");';

        echo '</script>';

        echo '<noscript>';

        echo '<meta http-equiv="refresh" content="0;url='.htmlspecialchars($url, ENT_QUOTES).'" />';

        echo '</noscript>';

    }

    exit;

}</strong>

 </p>

<p>

<strong>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
웅푸
5개월 전

function goto_url($url) {     run_event('goto_url', $url);

    if (function_exists('safe_filter_url_host')) {         $url = safe_filter_url_host($url);     }

    // 줄바꿈 문자 및 앞뒤공백 불필요한 문자를 제거 및 XSS 공격방지     $url = str_replace(["\r", "\n", "%0A", "%0D"], "", $url);     $url = trim($url);      $url = htmlspecialchars($url, ENT_QUOTES);

    if (!headers_sent()) {         header("Location: " . $url);     } else {         echo '';         echo '';     }

    exit; }

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

울라프
5개월 전
설명 좀 부탁해요
웅푸
5개월 전
function goto_url($url)
{
// URL 이동을 기록하거나 관련된 처리를 수행
run_event('goto_url', $url);

// URL을 필터링하는 함수가 존재하면?
if (function_exists('safe_filter_url_host')) {
$url = safe_filter_url_host($url);
}

// 불필요한 문자 제거 및 XSS방지, 줄바꿈 문자 제거 (header() 오류 방지)
$url = str_replace(["\r", "\n", "%0A", "%0D"], "", $url);

// 앞뒤 공백 제거 및 방지
$url = trim($url);

// HTML 특수 문자 변환 및 XSS 공격 방지
$url = htmlspecialchars($url, ENT_QUOTES);

if (!headers_sent()) { // 헤더가 이미 출력되지 않았다면
header("Location: " . $url);
} else { // 만약 헤더가 이미 출력되었을 경우 스크립트를 사용한 URL 이동
echo '<script>';
echo 'location.replace("' . $url . '");';
echo '</script>';

// 스크립트 사용할 수 없는 환경에서는 HTML 메타 태그를 이용해 이동
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
echo '</noscript>';
}
exit;
}

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인