Send hidden parameters to another page without showing them in the URL

Asked

Viewed 925 times

0

After doing a search on a form method POST.

<form method="POST" action="../controller/precontBuscaProg.php">
  <input type="date" name="dataini">
</form>

I receive on another page what was sent receiving the data so:

$dataIni = $_POST['dataini'];
$dataFim = $_POST['datafim'];
$dstPost = $_POST['dst'];
$orgPost = $_POST['org'];
$stPost = $_POST['st'];

$objProg = new Prog();
$objProg->setdataoprini($dataIni);
$objProg->setdataoprfim($dataFim);
$objProg->setdest($dstPost);
$objProg->setorig($orgPost);
$objProg->setst1($stPost);

$params= '?'.http_build_query(array('dataini'=> $dataIni, 'datafim'=>$dataFim, 'dst'=> $dstPost, 'org'=> $orgPost, 'st'=> $stPost));
header('location: ../view/programacao.php'. $params);

Returns me in the url this. Is there any way to hide this in the url ?

programacao.php?dataini=2016-08-16&datafim=2016-10-29&dst=%25%25&org=%25%25&st=1

And leave this alone ?

programacao.php

If there is another way besides . htaccess would like to know.

  • First if it’s generating it, it’s not doing post but get

  • That, thank you I will edit the question.

  • @Otto you need to change the method="get" to method="post", in the form tag, or if it doesn’t exist you add method="post". You will also need to change the way php will receive this data

  • @Fabianocacinpinel in my form is POST. Ai I get them so $dataIni = $_POST['dataini'];. After receiving send them by a header('location: ../view/programacao.php'. $params); to another page getting so like this in question. And I get them from ulr with a $_GET.

  • @Fabianocacinpinel if you pay attention the question is not mine, so I suppose the comment is for the owner of the post

  • @Kevin. F get sends everything by post url no, follow the tip of Fabiano that will be the way you want

  • @Otto, sorry, it was for Kevin.

  • @Kevin do a post redirect search so here I found an example I don’t know if it works http://stackoverflow.com/questions/3045097/php-redirect-and-send-data-via-post . But if the goal is to hide the information you can try encryption and then decryption

  • @Kevin another way to store them in a session and retrieve them later

Show 4 more comments

1 answer

-1

Whereas the purpose is unknown and disregarding SEO issues,

maybe, something that solves is to store in a session variable.

In this final chunk, instead of building a URL, save to a session variable

$params= '?'.http_build_query(array('dataini'=> $dataIni, 'datafim'=>$dataFim, 'dst'=> $dstPost, 'org'=> $orgPost, 'st'=> $stPost));
header('location: ../view/programacao.php'. $params);

Would look like this

$_SESSION['search'] = array(
    'dataini' => $dataIni,
    'datafim' => $dataFim,
    'dst' => $dstPost,
    'org' => $orgPost,
    'st' => $stPost
);

header('location: ../view/programacao.php?search='. $token);

On the page programacao.php, check the existence of the session according to the parameter search.

if (isset($_SESSION['search'])) {
    $parametros_busca = $_SESSION['search'];
}

I omitted the session_start() to simplify the teaching.

Basic example of how to use session variables:

http://www.w3schools.com/php/php_sessions.asp

https://stackoverflow.com/a/12368588/1685571

Obs: Something confusing about your question is that the title points one way and the context shows another. In the end, I interpreted that it has nothing to do with rewrite URL. Unless I state otherwise more clearly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.