隐藏获取变量

发布于 2024-09-17 16:39:09 字数 589 浏览 3 评论 0原文

我有一个使用 get 变量构建的 url,

location.href = this.href +'?type='+ escape($('#type_of_station').html()) + '&count='+ escape($('.number_changer').attr("id").slice(-1));

它给了我一个如下页所示的 url

http://posnation.com/pre_config/pre_config_step_2.php?type=Grocery&count=2 

我通过 PHP 获取变量

<p id="type_of_station" class="text left"><?php $_GET['type'] != "" ? print str_replace("_", " ", $_GET['type']) : print "Food Pos System" ?></p>

这很好用,但 url 有点难看。有没有办法隐藏它,并且在下一页上仍然可以使用获取变量

I have a url that is constructed using get variables like

location.href = this.href +'?type='+ escape($('#type_of_station').html()) + '&count='+ escape($('.number_changer').attr("id").slice(-1));

which gives me a url like the following

http://posnation.com/pre_config/pre_config_step_2.php?type=Grocery&count=2 

on the following page I grab the variables via PHP

<p id="type_of_station" class="text left"><?php $_GET['type'] != "" ? print str_replace("_", " ", $_GET['type']) : print "Food Pos System" ?></p>

This works great but the url is kind of ugly. Is there a way to maybe hide this and still have the get variables available to me on the next page

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萤火眠眠 2024-09-24 16:39:09

让 url 看起来漂亮是一回事。
隐藏 url 数据是另一回事。永远不要隐藏任何事情。否则您的网站将无法使用。

To make url look nice is one thing.
To hide url data is another. Never hide anything. Or you will make your site unusable.

够钟 2024-09-24 16:39:09

您希望将变量 POST 到服务器,而不是作为 GET 请求发送它们。

在 PHP 中,您可以使用 $_POST 变量访问 POST 变量。

简单形式:

form.php

<form action="process.php" method="POST">
   username: <input type="text" name="username" value="" /><br/>
</form>

可以在 process.php 文件中访问“用户名”POST。

然后, process.php

echo $_POST['username'];

与 GET 请求不同,发送到服务器的值不会显示在 URL 中。

You want to POST your variables to the server rather than sending them as GET requests.

In PHP you can access the variables POST-ed with the $_POST variable.

Simple form:

form.php

<form action="process.php" method="POST">
   username: <input type="text" name="username" value="" /><br/>
</form>

The 'username' POST-ed could then be accessed in the process.php file by

process.php

echo $_POST['username'];

Unlike GET requests, values sent to the server are not shown in the URL.

別甾虛僞 2024-09-24 16:39:09

使用 $_POST 而不是 $_GET,或者将它们保存在会话中并转到下一页。

编辑:
也就是说,如果您确实想要完全隐藏变量。正如其他人所建议的:最好使用 mod_rewrite 使其看起来更好,而不隐藏数据。

Either use $_POST instead of $_GET, or save them in a session and go to the next page.

EDIT:
That is if you really want to completely hide the variables. As the others are suggesting: it's better to use mod_rewrite to make it look nicer, without hiding the data.

极度宠爱 2024-09-24 16:39:09

我在你关于为这个问题寻找解决方案的帖子上发现了.. - 即使这是一个迟到的答案,也许它会对某人有所帮助:

对于我的使用,我得到了一个简单的解决方案:

只需在启动后添加到你的index.php文件中php session 以下行:

if(isset($_GET))
{
header("Location:index.php");
$_SESSION['relink'] = $_GET;
}

您将在 SESSION['relink'] 变量中拥有任何 GET 值。然后重定向到index.php 文件。您的浏览器地址中将会有任何可见的痕迹。您可以在使用数组之前检查数组的任何值。但至少你的浏览器地址是干净的!

I fell on your post on searching solutions just for this problem.. - and even it is a late answer, maybe it will help someone:

For my use, I got a simple solution:

Just add into your index.php file after starting the php session the following line:

if(isset($_GET))
{
header("Location:index.php");
$_SESSION['relink'] = $_GET;
}

You will have any GET value in the SESSION['relink'] variable. And then you redirect to the index.php file. There will be any visible traces in your browser address. After it is on you to check any value of the array before using it. But at least your browser address is CLEAN!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文