这是功能测试输入:
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
我将网站切换到seo_url
news_url
news_url看起来像:
domain.com/title /
htaccess的网址是:
RewriteRule ^([a-zA-Z0-9_-]+)/$ detail.php?p=$1 [NC,L]
我的问题是,当我单击链接并转到帖子详细信息页面(detail.php)时,如果输入的网址正确,则找到正确的帖子。 例: 如果即将到达的网址是:
domain.com/test /
它可以正常工作,但是如果它的网址错误,例如:
domain.com/testt/
出现如下所示的错误,该行应将url重定向到错误页面,但不会重定向。
警告:无法修改标头信息-标头已由发送 (输出从D:\ wamp \ www \ project \ heads \ nav.php:18开始) D:\ wamp \ www \ project \ detail.php在第57行
这是我的detail.php代码:
// Check existence of id parameter before processing further
if(isset($_GET["p"]) && !empty(test_input($_GET["p"]))){
$seourl = test_input($_GET['p']);
$stmt = $pdo->prepare("UPDATE posts set hits = hits + 1 where news_url = :news_url");
$stmt->execute(array('news_url'=>$seourl));
unset($stmt);
// Prepare a select statement
$sql = "SELECT * FROM posts WHERE news_url = :news_url";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":news_url", $param_seo_url);
// Set parameters
$param_seo_url = htmlspecialchars($seourl);
// Attempt to execute the prepared statement
if($stmt->execute()){
if($stmt->rowCount() == 1){
/* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// Retrieve individual field value
$title = test_input($row["title"]);
$subject = test_input($row["subject"]);
$detail = $row["detail"];
$img = test_input($row["img"]);
$hit = filterNum($row["hits"]);
$keywords = test_input($row["keywords"]);
$id = filterNum($row["id"]);
} else{
// URL doesn't contain valid id parameter. Redirect to error page
//This is not redirecting to error page
header("location: error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
} else{
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
和在nav.php中的代码错误提及:
$place = filterString(1);
$get_function = katplacegetir($place);
foreach($get_function as $rowd){ ?>
<li><a href="category/<?php echo $rowd['seo_url'];?>/"><?php echo $rowd['cat_name'];?></a></li>
<?php } unset($stmt);?>
<?php
$place = filterString(1);
$get_function = postplace($place);
foreach($get_function as $rowd){ ?>
<li><a href="<?php echo $rowd['news_url'];?>/"><?php echo $rowd['title'];?></a></li>
<?php } unset($stmt);?>
问题解决了,伙计,谢谢,我进行了第二次查询 news_url是我删除了它的问题,现在一切正常。