隐藏参数(查询字符串)的URL(htaccess的),但发送该参数的页面(PHP) [英] hide parameter (query string) in url (htaccess) but send this parameter to a page (php)

查看:361
本文介绍了隐藏参数(查询字符串)的URL(htaccess的),但发送该参数的页面(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏URL参数(QUERY_STRING),但将其发送到页面隐藏的,不可见的地址栏
例如:
我有这样的:

How to hide parameters (query_string) in url but send them to page hidden, not visible in address bar
example:
I have this:

http://localhost/index.php?sent=true

我想:

http://localhost/index.php

但我想在PHP $ _GET获得发送参数['发送']

but i want to get sent parameter in PHP $_GET['sent']

我试图重定向到网页不带参数(无QUERY_STRING)[R],并且给出页面经过一些参数(默默)无[R]重定向(不更改联系地址本身)

i tried to redirect to page with no parameters(no query_string) [R] and after that give page some parameters (silently) without [R] redirection (without changing adress itself)

我试图用重写规则的htaccess的标志不同的,不同的方式,但毫无效果

i tried to use RewriteRule in htaccess with different flags and different ways but nothing worked

我知道,如果我想改变地址,浏览器,我必须使用R标志为L标志在一个重写规则行 - 这是行不通的另一种方式 - 联系地址并没有改变

i learned that if i want to change address in browser, i must use R flag with L flag in one RewriteRule line - other way it does not work - adress does not change

但是当我使用[L]标志,我不能去下一行(下一个重写规则),并追加任何QUERY_STRING来解决,而不[R]重定向

but when i use [L] flag i cannot go to next line(next RewriteRule) and append any query_string to address without [R] redirection

如果我不把一个[L]标志的第一行(用[R])我没有新的地址,但如果我这样做 - 我不能使用[C]标志,甚至[N]标志

if i don't put an [L] flag in first line (with [R]) i don't have new address but if i do - i can't use [C] flag or even [N] flag

这是为什么:

在我的网页我用头('位置:...发送=真的吗?')的形式发送成功的数据后功能 我重定向到?发送= true,因为我不希望用户刷新页面,并再次发送相同的数据。

on my page i use header('Location: ...?sent=true') function after successful data sent from Form i redirect to ?sent=true because of i don't want to user refresh page and send the same data again

但重定向后?发送=真的,我不希望有一个QUERY_STRING在地址栏 有一些网页上更多的形式,将发送其它POST数据,并与这种丑恶QUERY_STRING有

but after redirect to ?sent=true i don't want to have that query_string in address bar there are more forms on that page that will send other POST data and refresh page with this ugly query_string there

该怎么做?

推荐答案

您可以设置它,这样,如果你访问与脚本?发送=真一旦最终,它会将用户重定向

You could just set it so that if you visit a script with ?sent=true once it has finished, it redirects the user

例如。

if(!empty($_GET['sent'])&&$_GET['sent']) {
    //do stuff
    header("Location: http://localhost/index.php");
}

您不能htaccess的,因为你需要传递给PHP做到这一点,它的通过,所以如果你使用重定向htaccess的价值将永远到不了PHP重定向后到PHP。

You can't do this with htaccess as you need to pass to PHP, it's passed to PHP after redirection so if you redirect with htaccess the value will never get to PHP.

另外的问题,要做到这一点,那么唯一的办法就是将用户与一个JavaScript形式

Further question, the only way to do this then is to redirect the user with a javascript form

<?php if(!empty($_GET['sent'])&&$_GET['sent']) { ?>
<form action='http://localhost/index.php' method='post' name='frm'>
    <?php
    foreach ($_GET as $a => $b) {
        echo "<input type='hidden' name='".$a."' value='".$b."'>";
    }
    ?>
    </form>
    <script language="JavaScript">
        document.frm.submit();
    </script>
<?php } ?>

这篇关于隐藏参数(查询字符串)的URL(htaccess的),但发送该参数的页面(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆