【发布时间】:2016-07-11 03:23:13
【问题描述】:
所以我有一个html 文件和一个php 文件,我想做的是将html URL 参数中的值传递给我的php。
例如,如果 URL 是localhost\files\reset_username.html?args=erft5467uio$d - 那么erft5467uio$d 位应该在我的php 的$_GET('args') 中被捕获。问题是这个值没有被传递到php 文件本身。
这是html 文件:
<html>
<form id='setUsername' action='setnewusername.php' method='post'>
<label for='username' >New Username: </label>
<input type='text' name='usernameInput' id='username' />
<label for='newUsername' >Confirm Username: </label>
<input type='text' name='newUsernameInput' id='newUsername' />
<input type='text' name='Submit' value='Change Username' />
</form>
</html>
这是我的php 代码:
<?php
require "init.php";
if(!empty($_GET['args']) && !empty($_GET['usernameInput'])){
$paramOne = $_GET['args'];
$paramTwo = $_GET['usernameInput'];
echo $paramOne;
echo $paramTwo;
}
else{
echo "The args was not received";
}
?>
当我测试我的代码时,php 打印出"The args was not received"。这意味着erft5467uio$d 的值没有被传递。
如何将这些值传递给php 脚本?
编辑:
每次用户请求更改其用户名时,他们都会收到一个带有唯一 args 值的链接。在这种情况下,用户会收到一封电子邮件,其中包含localhost\files\reset_username.html?args=erft5467uio$d 在这种情况下指向他们的电子邮件的链接。当他们单击链接时,他们将被定向到 html 页面。填写表格后,代码erft5467uio$d 以及usernameInput 必须传递给php
谢谢
【问题讨论】:
-
咳咳 =>
method='post' -
正如 Fred 所说,您应该使用
$_POST['args']。通常$_GET请求被<a href="url/to/file?args=data">link</a>使用 -
...或
method='get'或将其作为附加参数传递给您的action='setnewusername.php'。action='setnewusername.php?arg...' -
对 html 文件的请求中的 GET 参数将永远到达 php 脚本,除非您以非常奇怪的方式配置了 http 服务器。
-
是的,但用户会收到一封电子邮件,其中包含
localhost\files\reset_username.html?args=erft5467uio$d在这种情况下指向他们的电子邮件的链接。当他们单击链接时,他们将被定向到 html 页面。填写后,代码erft5467uio$d必须传递给php