好的,所以当我运行此脚本从论坛帖子中删除用户评论时,$ _SESSION [' id'](用户的mysql ID)会更改为$ postid(论坛帖子的ID)。我没有调用任何函数来设置它,并且在初始化会话时调用session_write_close();
。
<?php
session_start();
// I'm not showing connection code.
if(isset($_SESSION['user'])){
$user = mysql_real_escape_string($_SESSION['user']);
$userid = mysql_real_escape_string($_SESSION['id']);
$id = mysql_real_escape_string($_GET['id']);
$postid = mysql_real_escape_string($_GET['article']);
$result = mysql_query("DELETE FROM `______`.`______` WHERE `userid`='$userid' AND `id`='$id' AND `user`='$user'")or die(mysql_error());
if(mysql_affected_rows($result) == 1){
mysql_query("UPDATE `_______`.`______` SET `points`=`points`-'1' WHERE `id`='$userid' AND `username`='$user'")or die(mysql_error());
mysql_query("INSERT INTO `________`.`_______` (`user`,`userid`,`amount`,`reason`) VALUES('$user', '$userid', '-1', 'Removed a comment')")or die(mysql_error());
}
mysql_close($con);
ob_start();
header("location:../view-article?id=$postid");
ob_end_flush();
} //if there is a user
else {
ob_start();
header("location:http://boundsblazer.com/not-logged-in?url=articles.view-article:id=$postid");
ob_end_flush();
}
?>
答案 0 :(得分:2)
如果register_globals
已启用,则此行
$id = mysql_real_escape_string($_GET['id']);
可能会更改$_SESSION['id']
的值。所以请在register_globals
关闭时再试一次。