【问题标题】:post to url masking the query发布到 url 屏蔽查询
【发布时间】:2017-03-08 22:40:07
【问题描述】:

我有一个发布变量并获取它们的脚本,问题是页面的 URL 包含变量。

有没有办法隐藏url中的变量。

例如,网址显示为

http://localhost/try.php?js_var=123abc

有没有办法把代码改成打印

http://localhost/try.php

javascript和html

    <html>
<head>
</head>
<body>
<a href="#" id="link">Click me!</a>

<script>
    var js_var = "123abc";

    document.getElementById("link").onclick = function (e)

    {
        window.location = "try.php?js_var=" + js_var;


    }
</script>


</body>
</html>

try.php

<?php
if (isset($_GET['js_var'])) $php_var = $_GET['js_var'];
else $php_var = "<br />js_var is not set!";

echo $php_var;
?>

【问题讨论】:

  • 你确定这个" window.location = "try.php?js_var=" + js_var;"是 POST 吗?
  • GET 请求将始终在 url 中显示查询字符串。如果您想隐藏它,请将其添加到表单中的&lt;input type="hidden" /&gt; 字段并使用POST 方法...

标签: javascript php post get masking


【解决方案1】:

我认为没有办法隐藏变量,但你可以使用POST 方法和form 标签。有关 GET 与 POST 的一些信息 - http://www.w3schools.com/TAGS/ref_httpmethods.asp

【讨论】:

  • window.location = "try.php?js_var=" + js_var; !== 发布
  • 你也可以使用 $.post() 或 $.ajax() 和 post 方法
猜你喜欢
  • 2012-12-10
  • 1970-01-01
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 2015-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多