1

这是删除链接的代码:

<a href="picture_manager.php?do=delete&id=<?php print $picturedata['id']; ?>" >Delete</a>

这是我当前的数据库语法:

if (array_key_exists('do', $_GET) && $_GET['do'] == "delete" && array_key_exists('id', $_GET))
{
    $pictureid = trim(sanitize($_GET['id']));

    if ($picture->delete($pictureid) === true)
    {
        header('Location: picture_manager.php?success=removed');
    }
}

使用上面的代码,其他用户可以删除其他用户图片,例如 = picture_manager.php?do=delete&id=(victim)。

现在我找到了防止其他用户滥用的解决方案,我将旧语法更改如下:

这是我的新数据库语法:

if (!array_key_exists('id', $_GET) || $_GET['id'] == "" || $picture->pictureExists(trim(sanitize($_GET['id']))) === false || $picture->checkOwn($user->getUserID(trim(sanitize($_SESSION['key']))), trim(sanitize($_GET['id']))) === false)
{
    header('Location: picture_manager.php');
}
else    
{
    $pictureid = trim(sanitize($_GET['id']));

    if ($picture->delete($pictureid) === true)
    {
        header('Location: picture_manager.php?success=removed');
    }
}

可悲的是,它没有工作“页面没有正确重定向 - 说Firefox浏览器”

马上找高手。

我在下面的答案中找到了解决方案。

现在编辑:当我编码如下时,这对我来说很难:

if (isset($_GET['do']) && $_GET['do'] == 'delete' && (!array_key_exists('id', $_GET) || $_GET['id'] == "" || $picture->pictureExists(trim(sanitize($_GET['id']))) === false || $picture->checkOwn($user->getUserID(trim(sanitize($_SESSION['key']))), trim(sanitize($_GET['id']))) === false))
{
    header('Location: picture_manager.php');
}
else    
{
    $pictureid = trim(sanitize($_GET['id']));

    if ($picture->delete($pictureid) === true)
    {
        header('Location: picture_manager.php?success=removed');
    }
}

当我点击 ie picture_manager.php?do=delete&id=6125 时文件没有被删除

我的代码有什么问题?

4

1 回答 1

2

无限重定向, !array_key_exists('id', $_GET) 将始终进行。您需要将 ?do=delete 添加到验证中,例如

<?php if (isset($_GET['do']) && $_GET['do'] == 'delete' && (!array_key_exists('id', $_GET) || $_GET['id'] == "" || $picture->pictureExists(trim(sanitize($_GET['id']))) === false || $picture->checkOwn($user->getUserID(trim(sanitize($_SESSION['key']))), trim(sanitize($_GET['id']))) === false))
于 2013-04-14T14:20:46.483 回答