链接的 isset - PHP

发布于 2025-01-03 20:28:53 字数 795 浏览 0 评论 0原文

我正在尝试创建一个链接供用户单击,将其从列表中删除。我试图弄清楚如何在不使用提交按钮且不使用 $_GET(如果可能)的情况下执行此操作。

不管怎样,我害怕用 $_GET 来做到这一点(我现在的方式),因为用户可以在 URL 中输入这个(即使 99% 的人不知道如何或不知道如何做到这一点),他们会从列表中删除。

如何命名链接以便可以使用 $_POST?

$attendingUsers = mysql_query("Select acceptedInvites from events where eventID = ".mysql_real_escape_string($_GET['eventID'])." ");
    $users= mysql_fetch_array($attendingUsers);
    $user = $users['acceptedInvites'];
 if(preg_match("/$userid/", $user)){
        echo "You are attending this event</br>";
        echo '<a href="viewevent.php?eventID='.$_GET['eventID'].'&delete=1">Click here </a>to remove yourself from the list';
            if($_GET['delete']=1){
                    $sql=...
        }
    }   

不使用 $_GET 是否可以做到这一点?谢谢!

I'm attempting to create a link for users to click that will remove them from a list. I'm trying to figure out how to do this without using a submit button and without using $_GET(if possible).

Anyway, I'm afraid to do it with $_GET (the way I have it now), because the user can type this in the URL (even though 99% wouldn't know how or think to do this) and they would be removed from the list.

How can I name the link so I can use $_POST?

$attendingUsers = mysql_query("Select acceptedInvites from events where eventID = ".mysql_real_escape_string($_GET['eventID'])." ");
    $users= mysql_fetch_array($attendingUsers);
    $user = $users['acceptedInvites'];
 if(preg_match("/$userid/", $user)){
        echo "You are attending this event</br>";
        echo '<a href="viewevent.php?eventID='.$_GET['eventID'].'&delete=1">Click here </a>to remove yourself from the list';
            if($_GET['delete']=1){
                    $sql=...
        }
    }   

Is it possible to do this without using $_GET? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

揽月 2025-01-10 20:28:53

切勿通过链接删除。阅读末日蜘蛛

最好的方法是链接到带有“你是吗”的“删除”页面确定”的形式。提交表单(通过 POST)执行删除并重定向回合适的结果页面。

例如

<a href="remove.php?eventID=<?php echo $eventId ?>">Click here</a>
to remove yourself from the list

,然后,在 remove.php 中,

<?php
// get Event details via $_GET['eventID']

if (isset($_POST['confirm'])) {
    // delete via SQL

    // redirect
    header('Location: http://example.com/events.php');
    exit;
}

// display event details
?>

<form method="post" action="remove.php?eventID=<?php echo $eventId ?>">
    <p>Are you sure?</p>
    <input type="submit" name="confirm" value="Remove me from this event">
</form>

您可能还应该研究 CSRF 保护,但这确实超出了这个问题的范围。

Never delete via a link. Read The Spider of Doom

Best way is to link to a "delete" page with an "are you sure" form. Submitting the form (via POST) performs the delete and redirects back to a suitable results page.

For example

<a href="remove.php?eventID=<?php echo $eventId ?>">Click here</a>
to remove yourself from the list

Then, in remove.php

<?php
// get Event details via $_GET['eventID']

if (isset($_POST['confirm'])) {
    // delete via SQL

    // redirect
    header('Location: http://example.com/events.php');
    exit;
}

// display event details
?>

<form method="post" action="remove.php?eventID=<?php echo $eventId ?>">
    <p>Are you sure?</p>
    <input type="submit" name="confirm" value="Remove me from this event">
</form>

You should probably also look into CSRF protection but that's really outside the scope of this question.

家住魔仙堡 2025-01-10 20:28:53

您需要使用 $_GET$_POST

<form action="delete.php" method="post">
   <input type="hidden" name="eventId" value="yourEventId" />
   <a href="#" onclick="this.form.submit();" > Delete</a>
</form>

Your are required to use either $_GET or $_POST

<form action="delete.php" method="post">
   <input type="hidden" name="eventId" value="yourEventId" />
   <a href="#" onclick="this.form.submit();" > Delete</a>
</form>
我是有多爱你 2025-01-10 20:28:53

如果我的 JavaScript 正确,这应该可以解决问题:

<a href="javascript:void(document.getElementById('delete').submit());">Delete</a>
<form id="delete" action="delete.php" method="post">
    ...
</form>

链接将提交表单。

If I have my JavaScript right, this should do the trick:

<a href="javascript:void(document.getElementById('delete').submit());">Delete</a>
<form id="delete" action="delete.php" method="post">
    ...
</form>

The link will then submit the form.

阳光下的泡沫是彩色的 2025-01-10 20:28:53

您可以使用某种编码使 get var 不可读,例如 md5 甚至加密字符串。

You could use some kind of encoding to make the get var unreadable, like an md5 or even an encrypted string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文