http:// 를 https:// 로 이동하는 방법
header 를 이용하는 방식과 javascript 를 이용하는 방법을 안내합니다.
방식은 PHP 페이지 최상단에서 위치해야 정상 작동하며, 강력하게 작동합니다.
javascript는 페이지 상단이 아니어도 작동하지만, javascript를 제한한 경우에 작동하지 않습니다.
1. header location 이용
<?php
if($_SERVER['HTTPS'] != "on"){
$ssl_port = ""; // 443 포트를 사용하지 않는경우에 이용할 포트번호 입력
if ($ssl_port == "") {
$redirect_URL = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} else {
$redirect_URL = "https://".$_SERVER['HTTP_HOST'].":".$ssl_port.$_SERVER['REQUEST_URI'];
}
header("Location: ".$redirect_URL);
}
?>
2. javascript 이용
<?php
if($_SERVER['HTTPS'] != "on"){
$ssl_port = ""; // 443 포트를 사용하지 않는경우에 이용할 포트번호 입력
if ($ssl_port == "") {
$redirect_URL = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} else {
$redirect_URL = "https://".$_SERVER['HTTP_HOST'].":".$ssl_port.$_SERVER['REQUEST_URI'];
}
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
//echo "location.href = '". $redirect_URL ."';\n"; // 현재창으로 전송
echo "parent.location.href='". $redirect_URL ."';\n"; // 부모창으로 전송
echo "//-->\n";
echo "</script>\n";
}
?>
참고자료
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4706 | jQuery | 8년 전 | 1517 | ||
| 4705 | jQuery | 8년 전 | 2180 | ||
| 4704 | jQuery | 8년 전 | 1712 | ||
| 4703 | jQuery | 8년 전 | 2048 | ||
| 4702 | jQuery | 8년 전 | 1838 | ||
| 4701 | jQuery | 8년 전 | 2071 | ||
| 4700 | jQuery | 8년 전 | 1750 | ||
| 4699 | jQuery | 8년 전 | 1532 | ||
| 4698 | jQuery | 8년 전 | 1340 | ||
| 4697 | jQuery | 8년 전 | 1755 | ||
| 4696 | jQuery | 8년 전 | 2375 | ||
| 4695 | jQuery | 8년 전 | 1391 | ||
| 4694 | jQuery | 8년 전 | 1805 | ||
| 4693 | jQuery | 8년 전 | 1781 | ||
| 4692 | jQuery | 8년 전 | 2575 | ||
| 4691 | jQuery | 8년 전 | 2081 | ||
| 4690 | jQuery | 8년 전 | 1971 | ||
| 4689 | jQuery | 8년 전 | 1950 | ||
| 4688 | jQuery | 8년 전 | 1709 | ||
| 4687 | jQuery | 8년 전 | 1121 | ||
| 4686 | jQuery | 8년 전 | 1753 | ||
| 4685 | jQuery | 8년 전 | 2497 | ||
| 4684 | jQuery | 8년 전 | 2377 | ||
| 4683 | jQuery | 8년 전 | 1772 | ||
| 4682 | PHP | 8년 전 | 3094 | ||
| 4681 | jQuery | 8년 전 | 1612 | ||
| 4680 | jQuery | 8년 전 | 1800 | ||
| 4679 | PHP | 8년 전 | 2026 | ||
| 4678 | PHP | 8년 전 | 2159 | ||
| 4677 | PHP | 8년 전 | 2260 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기