First of all, thank you for trying to help for me. :)
We have a Windows Server with PHP sites, mysql databases. The windows Server version is which doesn't support the .htacces yet, and because of this, we have a rule, thar every 404 error has been reditect to a redirect.php.
Of course, we have a session handlers, which writes to the session table
The problem is with the post and get to niceurl. I had a solution, to skip this, what is about to set the form action to redirect.php what is set the $_SESSION['lastPost'] variable equal to the $_POST except $_POST['redirect'] what is the redirection url. When i redirected to the url ($_POST['redirect']), i take back the $_SESSION['lastPost'] to the $_POST and unset($_SESSION['lastPost']).
That has been worked perfectly, until the search. Because of the search works with ajax, i had to set the search parameters to the $_SESSION, and after that, i cannot unset the $_SESSION variables. ( Auto Globals is ON on our server too )
If i comment the rows where the $_SESSION values has been set, that works perfectly.
I know that i should not manipulate superglobals, but because of the nice-url, i could not solve otherwise.
I read the most of session unset, and session delete problems, but there is not my solution. I have session_start(); I tried after the last $_SESSION variable assignment to session_write_close(); but it did not help for me.
redirect.php
require_once("###########/inc/session.php"); //that is the right location
if (isset($_POST['redirect']) && !empty($_POST['redirect'])) {
$strRedirect = $_POST['redirect'];
unset($_POST['redirect']);
$_SESSION['lastPost'] = $_POST;
unset($_POST);
redirect(urldecode($strRedirect));
exit();
}
search.php
require_once("###########/inc/session.php"); //that is the right location
if (isset($_SESSION['lastPost']) && !empty($_SESSION['lastPost'])) {
$_POST = $_SESSION['lastPost'];
unset($_SESSION['lastPost']);
}
//if i comment out the session variable assignment below, the $_SESSION['lastPost'] will become null, as it has to, otherwise it will never
if (!empty($_POST['job_types_id'])) {
$strJobTypesWhere = "`job_types_id` = '" . (int) $_POST['job_types_id'] . "'";
$_SESSION['job_search'][] = $strJobTypesWhere;
}
When i post first time, works fine, the $_POST gets the $_SESSION['lastPost'] value, and after that, when i dump the $_SESSION['lastPost'] is null, and here should be the over... After a simple refresh on the nice url without posting to the redirect, the $_SESSION['lastPost'] contains the previous $_POST... and i cannot remove
Thanks for trying help for me, and sorry for my english :))
unset
, try printing the value of$_SESSION['lastPost']
, if it doesn't display your code works fine and somewhere it's re-adding it. Try to debug by displaying it wherever possible. – AyB Mar 5 '14 at 6:31$_POST = $_SESSION['lastPost'];
because the$_POST
needs to come only after the form has been actually submitted. Why not use a normal array for this? And not sure if this is useful, but on refresh of page, your POST values will be resubmitted. – AyB Mar 5 '14 at 6:40