>  기사  >  백엔드 개발  >  PHP에서 웹페이지를 리디렉션하는 방법

PHP에서 웹페이지를 리디렉션하는 방법

coldplay.xixi
coldplay.xixi원래의
2020-09-01 13:47:272705검색

PHP에서 웹페이지를 리디렉션하는 방법: 1. [header()] 함수를 사용하여 리디렉션합니다. 2. HTML 헤더에 메타 태그를 사용합니다. 3. 점프하려면 자바스크립트를 사용합니다.

PHP에서 웹페이지를 리디렉션하는 방법

【관련 학습 권장 사항: php 그래픽 튜토리얼

PHP에서 웹 페이지를 리디렉션하는 방법:

hhw: 첫 번째 방법을 사용하여 페이지를 리디렉션합니다. :http: //127.0.0.1/tp5 http://127.0.0.1로 단순화되었습니다. 즉, 첫 번째 방법으로 www 디렉토리에 있는 index.php 파일을 PHP 코드에 작성합니다:

<?php
header(&#39;content-type:text/html;charset=uft-8&#39;);
header(&#39;location:tp5/index.php&#39;);
?>

또는 직접:

<?php
header(&#39;content-type:text/html;charset=uft-8&#39;);
header(&#39;location:tp5/public/index.php&#39;);
?>

첫 번째 방법: 헤더 사용 () 기능을 리디렉션하는데, 이것이 제가 더 많이 사용하는 것입니다. (참고! locationhe와 ":" 사이에는 공백이 있으면 안 됩니다. 그렇지 않으면 아무런 효과가 없습니다!)

<?php
header(&#39;content-type:text/html;charset=uft-8);
//重定向页面
header(&#39;location:index.php&#39;);
?>

두 번째: HTML 헤더의 메타 태그를 사용하여 http-equiv=refresh 및 content="시간을 정의하세요. 점프하는 데 소요되는 시간(초), url = 점프 주소”

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
//跳转页面,跳转时间:3秒钟,目标地址:index.php
<meta http-equiv="refresh" content="3;url=index.php">
<title>skip...</title>
</head>

또는

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$url=&#39;index.php&#39;;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
//跳转页面,跳转时间:2秒钟,目标地址:index.php
<meta http-equiv="refresh" content="2;url=<?php echo $url; ?>">
<title>skip...</title>
</head>

세 번째 방법: 자바스크립트를 사용하여 점프

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$url=&#39;index.php&#39;;
//立即跳转至目标页面
echo <script>window.location.href=&#39;$url&#39;;</script>;
?>

관련 학습 권장 사항: php 프로그래밍(동영상)

위 내용은 PHP에서 웹페이지를 리디렉션하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.