상대경로를 절대경로로 바꾸기
[code]
function rel2abs($relPath) {
$curPath = $_SERVER['PHP_SELF'];
$tmp = preg_replace("/\\/[^\\/]*$/", "/", $curPath) . $relPath;
$tmp = preg_replace("/\\/\\.\\//", "/", $tmp);
$c = preg_match_all("/\\.\\./", $tmp, $matches);
for ( $i = 0; $i < $c; ++$i )
$tmp = preg_replace("/\\/[^\\/]+\\/\\.\\.\\//", "/", $tmp, 1);
return $tmp;
}
echo G5_URL.rel2abs("../theme/basic/head.php");
[/code]
외부 페이지로 퍼가기 할 때 절대경로가 필요하더군요
고 때 사용하심 됩니다.
function rel2abs($relPath) {
$curPath = $_SERVER['PHP_SELF'];
$tmp = preg_replace("/\\/[^\\/]*$/", "/", $curPath) . $relPath;
$tmp = preg_replace("/\\/\\.\\//", "/", $tmp);
$c = preg_match_all("/\\.\\./", $tmp, $matches);
for ( $i = 0; $i < $c; ++$i )
$tmp = preg_replace("/\\/[^\\/]+\\/\\.\\.\\//", "/", $tmp, 1);
return $tmp;
}
echo G5_URL.rel2abs("../theme/basic/head.php");
[/code]
외부 페이지로 퍼가기 할 때 절대경로가 필요하더군요
고 때 사용하심 됩니다.
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 4개
변조를 통해 XSS 취약점 공격도 가능하기 때문에 SCRIPT_NAME 을 사용하시는 것이 좋습니다.
근데, 궁근한 게요,,,
위 본문처럼 함수를 정의하고 출력 코드 부분을
echo G5_URL.rel2abs("../theme/basic/head.php"); 이렇게 적는 경우와
그냥 단순히 위 본문의 함수 사용 않고,
echo G5_URL."/theme/basic/head.php"); 이렇게만 적는 경우가 차이가 있는 건가요?
theme/board/basic 에서 echo rel2abs("../../_common.php"); 를 실행하면
/_common.php 으로 됩니다.