if($api_response["success"] === true) {
header("Location: https://google.com");
exit;
} else {
// print_r($api_response);
$msg = "Some Error Occured!";
header("Location: ". $_SERVER['HTTP_REFERER']);
// echo $msg;
}
위 코드에서 참이면 코드가 완벽하게 작동하고 예상대로 리디렉션됩니다. 하지만 사실이 아닌 경우 오류를 표시하고 싶습니다.index.php
<?php
if(isset($msg) && $msg != ''){
echo $msg;
}
?>
조건이 거짓 일 때 $ msg 변수의 값을 얻지 못했습니다.
$msg
헤더로 보내기
if($api_response["success"] === true) {
header("Location: https://google.com");
exit;
} else {
$msg = "Some Error Occured!";
header("Location: ".$_SERVER['HTTP_REFERER']."?msg=".$msg);
}
다음을 읽고 $msg
다음과 같이
if(isset($_GET['msg'])){
print_r($_GET['msg']);
}
귀하의 경우에는 이와 같이 비공개로 유지하기 위해 세션을 사용해야합니다.
if($api_response["success"] === true) {
header("Location: https://google.com");
exit;
} else {
$msg = "Some Error Occured!";
session_start();
$_SESSION['msg'] = $msg;
header("Location: ". $_SERVER['HTTP_REFERER']);
exit();
}
//and read like this
<?php
session_start();
if(isset($_SESSION['msg'])){
echo $_SESSION['msg'];
unset($_SESSION['msg']); // remove it now we have used it
}
?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다