티스토리 뷰
You can cause your PHP script to sleep for 10 seconds,
sleep(10);
but this will appear to the end-user as a non-responsive server. The best option is to use either a meta refresh,
<meta http-equiv="refresh" content="10;url=http://google.com">
or javascript.
setTimeout(function(){
window.location = "http://google.com";
}, 10000);
Found in the comments from Daniel:
header('Refresh: 10; URL=http://yoursite.com/page.php');
would be ideal for this situation, as it requires no Javascript or HTML.
-------------------
header('Refresh: 10; URL=http://yoursite.com/page.php');
이 PHP 코드를 페이지의 헤더 섹션에 넣으십시오. 그렇지 않으면 작동하지 않습니다.-------------------
클라이언트 측 리디렉션을 원할 것입니다.
<meta http-equiv="refresh" content="5;url=http://yourdomain.com"/>
하지만 PHP에 있어야한다고 생각되면 다음과 같이 할 수 있습니다.
<?php
// wait 5 seconds and redirect :)
echo "<meta http-equiv=\"refresh\" content=\"5;url=http://yourdomain.com\"/>";
?>
-------------------
PHP 스크립트를 잠자기 상태로 만드는 것은 나쁜 생각입니다. 실제로 서버를 쉽게 DoS하는 방법입니다.;) 메모리의 PHP 스크립트는 특히 CGI로 작동하는 경우 충분한 리소스를 소비합니다.-------------------
<?php
header( "refresh:10; url=https://example.com/index.php" );
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirect with countdown</title>
<style type="text/css">
.myClass {
font-family: verdana;
font-size: 16px;
font-weight: normal;
color: black;
line-height: 30px;
}
</style>
</head>
<body>
<script type="text/javascript">
(function () {
var timeLeft = 10,
cinterval;
var timeDec = function (){
timeLeft--;
document.getElementById('countdown').innerHTML = timeLeft;
if(timeLeft === 0){
clearInterval(cinterval);
}
};
cinterval = setInterval(timeDec, 1000);
})();
</script>
Redirecting in <span id="countdown">10</span> seconds.
<br><br>
<span class="myClass">Thank you! Your submission has been received!</span>
</body>
</html>
-------------------
PHP는 서버 측에서 실행되고 지연되는 동안 사용자에게 유용한 피드백을 제공하지 않기 때문에 잘못된 기술 일 수 있습니다. 이것은 Javascript에서 많은 코딩이 아닙니다. 페이지에서이를 구현하는 매우 쉬운 방법 은
이 링크
를 참조하십시오.-------------------
웹 페이지가로드 된 후 PHP가 더 이상 실행되지 않습니다. 즉, AJAX (Javascript calling a PHP page)와 같은 것을 사용하여 페이지로 데이터를 전송하지 않는 한 페이지가로드 된 후에는 PHP로 아무것도 할 수 없습니다. 이것은 리디렉션시 원하는 10 초 대기를 달성하는 몇 가지 방법을 제공합니다.먼저 스크립트에 10 초 동안 sleep ()을 지시 할 수 있습니다. 그러나 Johnathan이 언급했듯이 이것은 사용자가 리디렉션되는 경우에만 페이지가 정말 느린 것처럼 보일 것임을 의미합니다.
sleep(10);
페이지가 10 초 후에 리디렉션되도록 지시하는 META 태그를 삽입 할 수도 있습니다. 이 방법은 거의 다른 코딩과 관련이 없기 때문에 선호되는 방법입니다. META 태그를 간단히 삽입하고 자바 스크립트를 전혀 다룰 필요가 없기 때문입니다.
<meta http-equiv="refresh" content="10;url=http://example.com"/>
그런 다음 Javascript가 location.href = "bleh"를 발행하도록 할 수도 있습니다. 10 초 동안 기다린 후 명령.-------------------
언급 할 가치가있는 또 다른 방법은 PHP의
header ()
함수 로 Location HTTP 헤더를 보내는 것입니다. 따라서 웹 애플리케이션의 응답 성을 유지하면서 자바 스크립트 및 메타 태그를 피하는 강력한 솔루션을 원한다면 iframe (또는 프레임)을 만들고 다음을 포함하는 PHP 스크립트를로드 할 수 있습니다.
sleep(10);
header("Location: http://my.redirect.location.com");
-------------------
이 스크립트를 시도하면 작동합니다!
<?php
$msg ="This Is Just Checking";
header('Refresh: 5; URL=http://www.google.com.pk');
?>
<body>
<?php echo $msg ?>
</body>
</html>
-------------------
나는 PHP에서 간단한 기능으로 그것을 할 수 있었다.
function RedirectToURL($url, $waitmsg = 0.4)
{
header("Refresh:$waitmsg; URL= $url");
exit;
}
리디렉션하기 전에 2 초 동안 PHP에서 호출합니다. $ waitmsg = 0.4는 기본값을 정의하는 데 사용됩니다.
RedirectToURL("http://website.php", 2);
양식 제출 후 리디렉션하려면 다음을 시도하십시오.
if(isset($_POST['submitted']))
{
echo '<div style="text-align:center; margin-left:auto; margin-right:auto"><br><br>Sucess. Thanks for contribution.</div>';
RedirectToURL("http://thewebsiteilookforaftersubmit", 2); // I want to wait 2 seconds and not 0.4 as defined by default
}
-------------------
코드가있는 파일 (예 : "go.php")을 만듭니다.
<?php
$site = $_GET['iam'];
sleep(5);
Header ("Location: ".$site."");
exit();
?>
<a href="http://whatever.com/go.php?iam=http://google.com">Link</a>
또는 이렇게 "수면"없이
<?php
$site = $_GET['iam'];
Header('HTTP/1.1 301 Moved Permanently');
Header("Refresh: 10; URL=".$site."");
exit();
?>
<a href="http://whatever.com/go.php?iam=http://google.com">Link</a>
출처
https://stackoverflow.com/questions/1901815