【问题标题】:Submit input value without the name in the URL在 URL 中提交不带名称的输入值
【发布时间】:2015-03-30 20:27:24
【问题描述】:

有没有办法在不获取 URL 名称的情况下提交输入字段值?

我使用带有方法 GET 的表单进行搜索,当我提交表单时,我得到如下信息:

/file/?inputname=value

我想这样得到它:

/file/value

否则:如果第一种解决方案不可行,我该如何修改.htaccess以上述方式重写URL(我的意思是:/file/?inputname=value),但请记住我在URL中使用了2个参数@ 987654324@

提前致谢

【问题讨论】:

  • 为什么你不能和post一起去??
  • 我真的考虑过,如果我们没有找到解决方案,我会这样做。
  • 如果您需要第二个输入值会怎样?
  • .htaccess RewriteRule 是解决方案。
  • 发布你当前的 RewriteRule/.htaccess

标签: php jquery forms .htaccess


【解决方案1】:

试试这个:Solution Here

像下面这样使用 .htaccess

RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]

对于您网站上的用户,他们会看到并导航到:

http://example.com/value

但真正的页面应该是这样的:

http://example.com/index.php?inputname=value

这个位,[L],告诉服务器这是重写规则的最后一行并停止。

【讨论】:

    【解决方案2】:

    将表单方法设置为发布

    <form method="post" ...
    

    并在您的PHP 文件中接收这样的数据

    $inputValue = $_POST['inputname'];
    

    【讨论】:

      【解决方案3】:

      第一个是不可能的。

      .htaccess:

      Options -MultiViews
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-l
      
      RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
      

      PHP

          $url = rtrim($_GET['url'], '/');
          $url = filter_var($url, FILTER_SANITIZE_URL);
          $url = explode('/', $url);
      
          $part1 = (isset($url[0]) ? $url[0] : null);
          $part2 = (isset($url[1]) ? $url[1] : null);
          $part3 = (isset($url[2]) ? $url[2] : null);
          $part4 = (isset($url[3]) ? $url[3] : null);
          $part5 = (isset($url[4]) ? $url[4] : null);
      
      /*
      $partN will contain the input after the URL. 
      If URL was http://foo.com/this/is/fun
      $part1 = this
      $part2 = is
      $paer3 = fun
      */
      

      【讨论】:

        【解决方案4】:

        你必须使用post方法。

        注意:POST 方法发送的数据通过 HTTP 标头,因此安全性取决于 HTTP 协议。通过使用 Secure HTTP,您可以确保您的信息是安全的。

        REFERENCE

        还有重写规则,试试这个

        RewriteEngine on
        RewriteRule ^dir1/file/$ http://www.my.domain.com/dir1/file [QSA,L]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多