3

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

i want:

http://localhost/index.php

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

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)

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

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

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

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


Here is why:

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

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

how to do that?

3 Answers 3

2

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

e.g.

if(!empty($_GET['sent'])&&$_GET['sent']) {
    //do stuff
    header("Location: http://localhost/index.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.


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 } ?>
Sign up to request clarification or add additional context in comments.

2 Comments

yes but i want to show message to the user after success, so i get $_GET['sent'] parameter from url and if there is one i show the message
that is good idea! thanks! i can even "draw" the forms on page with php with action parameter pointing to index.php too. but i'm curious if it is possible to send parameters without showing them in url? :)
1

You could assign the variable in apache:

SetEnvIf Request_URI "\sent=true$" SENT=1

then retrieve it in PHP like:

if (isset($_SERVER['SENT'])) {
   echo "Received sent variable from apache, value is " . $_SERVER['SENT'];
} else {
   echo "not received sent variable from apache";
}

UPDATE:
You need to set AllowOverride FileInfo or AllowOverride ALL in your httpd.conf file or .htaccess file, like this example:

<Directory /home>
 AllowOverride FileInfo
</Directory>

12 Comments

but what if i have many tabs open and i'm sending data simultaneously? the same problem is with cookies and sessions. apache variable, cookie or sessions are global for all pages/tabs in browser and user action is always specific to concrete tab
You are wrong, this apache variable is set in each request, not cached in any manner across sessions or the like, it's unique per page request.
i added this line to htaccess and output is "not received sent variable from apache"
You should have AllowOverride FileInfo in your .htaccess or httpd.conf file.
i don't have access to httpd.conf (not my server) but when i added AllowOverride FileInfo or even AllowOverride All nothing happened - only server error :)
|
0

Cookies may be a solution for this as you can use them to pass data from pages to pages and there are not visible, at least not easily for common users.

Or if possible for you, $_SESSION is also a good solution to send data from one page to the other.

1 Comment

but what if i have multiple pages open(tabs)? and i simultaneously submit forms? i will have one cookie with "sent" variable overwritten

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.