繁体   English   中英

使用标题位置后,php父页面重定向两次

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM