gpt4 book ai didi

php - HTML 按钮 : Redirect on click

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:54 26 4
gpt4 key购买 nike

<input type='submit' name='submit' value='Register' class='register' />

如何在点击时创建指向网站的链接?

最佳答案

这是使用 PHP 的 header() 对当前代码(提交类型按钮)执行此操作的一种方法功能。

(处理程序.php)

<?php
if(isset($_POST['submit'])){
header("Location: http://www.example.com/page.php");
exit;
}

我假设您在问题中使用的代码类似于以下影响:

<form action="handler.php" method="post">
Username:
<input type='text' name='username' />
<input type='submit' name='submit' value='Register' class='register' />
</form>

当然我没有包括可能的 $username=$_POST['username'];这可能在您的 PHP 中,具体取决于您将如何使用它。


编辑

阅读后 mplungjan's comment 进行了轻微的名称更改。我还不知道为什么要使用这个名字 submit在尝试在 Google 上找到(或一个)原因后,被认为是不安全的。我希望得到或找到这种影响的答案。

(Edit-findings) 请参阅下面我迄今为止发现的更多信息。

(处理程序.php)

<?php
if(isset($_POST['reg_button'])){
header("Location: http://www.example.com/page.php");
exit;
}

我假设您在问题中使用的代码类似于以下影响:

<form action="handler.php" method="post">
Username:
<input type='text' name='username' />
<input type='submit' name='reg_button' value='Register' class='register' />
</form>

调查结果:

我遇到过关于 mplungjan 的主题的文章评论中提到:


如果您要使用 PHP(服务器端)方法,请考虑使用从 this website's article on Cross site scripting. 借用的以下内容

<input name="foo" value="<?php print htmlspecialchars($foo); ?>">

在你的情况下:

<input type='submit' name='reg_button' value='<?php print htmlspecialchars($reg_button); ?>' class='register' />

借自 mplungjan's comment :

1) 永远不要调用提交按钮 name="submit"
2) 使用链接或按钮 <input type="button" onclick="location='somepage.html'" />
3) 只需使用 name="Submit"submitted这样就会避免出现问题。

(感谢您的额外输入 mplungjan)。

关于php - HTML 按钮 : Redirect on click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com