[英]php parent page redirect twice after using header location
我被困在我的PHP代碼中。 header()工作后,父PHP頁面再次重新加載,這是我的代碼
<?php
$mysqli = new mysqli("localhost", "root", "root", "testing");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql ="update test set hit_count = hit_count+1";
$result = $mysqli->query($sql);
header('Location: http://www.google.com/');
die();
?>
在這里,有時候我從數據庫獲得2 hit_count。 工作原理,我在header()之后添加了die()。
如下面的代碼所示,在使用標題重定向之前,您不應該輸出文本:
/* Select queries return a resultset */
if ($result = $mysqli->query($sql)) {
printf("updated");
}else{
echo "failed";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.