I would like to unset some specifics $_SESSION variables after leaving a page, but the problem is that I have used pagination (using $_GET) for all sections of my site (contacts.php?page=1, ?page=2, etc; actions.php?page=1,?page=2 etc .; customers.php?page=1,?page=2, etc ...).
For all the sections there are filters which, if set, are saved in some $_SESSION variables. Those variables must remain set when passing from ?page=1 to ?page=2 etc but it must be deactivated by switching from contacts.php to actions.php, otherwise in actions.php I will have the already setted filters that I had set in contacts.php!
Thanks!
PS Sorry for my english
You can set the key name to null or ''.
For example
$_SESSION['key_name']='';
$_SESSION['key_name']=NULL;
sessions are recognized by a session id. if you delete this id the whole session (with all these entries) will be deleted. Therefore you could set the specific values to "null" and delete them this way.
you could do this either on the next page load or with javascript "on unload".
To remove a session on some specific pages redirections pass some variable to the target page and check on that page if the key exists then use unset function
unset($_SESSION['key_name'])
In case you want to remove session completely use
session_destroy();
Related
I have a website where the user starts on one page and then moves to a second page. The first page initializes and adds values to a counting variable, which I then want to be able to be displayed on the second page. I know to use a session, but I am wondering how I should properly end the session--do I end it on the first page, or the second page? Do both pages need to begin with session_start()?
Yes. Both must use session start. The variable you are talking about is basically termed cookies. The variables will be shared throughout the browser sessions.
I have a big problem with Wordpress and can't find a solution.
I'm trying to make a value available from every *.php file.
I want with $_SESSION['session_id'] = $var; but I've read that in Wordpress Sessions are not available.
I've tried it but it looks like that my Session is only saved once and after page reload the value is gone.
On my second page I get the Session with $var = $_SESSION['session_id'];
I've tried it with session_start() in my init hook and on my pages too where I use the Sessions but no effect. Is there someone who has an idea who I can transmit my values from one page to another without cookies because I don't want the users to see the values.
I am setting session_start() on every page as very 1st statement.
The 1st page sets $_POST['myVar'] when the page ist submitted. The 2nd page evaluates this by a php lib which sets $_SESSION['myVar'] if this is set in $_POST and not set already in $_SESSION.
When submitting this form and calling the 3rd one evaluating there $_SESSION['myVar'] results that the variable is no more set! There is no session_unset() called between.
Theoretically all is correct but the use shows the opposite. What may there be wrong or still missing?
In the page you have a form, probably your first page session is not required. In the next page(form action page), you need to start the session first. Then you can give like $_SESSION['fieldName']=$_POST['fieldName']. After this in whichever pages you use session_start(), you can have the data. Hope this helps..
$_SESSION is successfully maintaining some fields across a page submit process, but ONLY those that are specifically conserved in my own, self-created $_SESSION initialisation function.
This would not be odd if my $_SESSION initialisation function was actually being called .. obviously!! Its whole purpose is to retain some key values, and wipe all the others from the $_SESSION array
However, this happens even when that function is NOT called by my code.
I have a View page including a form that is submitted, identifying a Control action file to trigger on submit.
I verify $_SESSION contents as part of the View page display. It displays the full set of $_SESSION array fields
I then do a print_r of $_SESSION contents immediately following session_start() in the identified Control file
Prior to the user hitting submit, the full set of $_SESSION values are there
Immediately after user hitting submit, most of them are gone, but anything I choose to retain on $_SESSION initialisation is retained.
NONE of my own code can possibly be running in between: there is pure PHP only there.
I had 2 theories on this.
1. PHP does something in the background and happens to have an internal function name that I used by mistake, which was then calling my function in preference to the system function of the same name, thus resulting in my $_SESSION getting initialised.
So I changed the function name (to clean_session()) -> same problem
Something about running the function when I initialise the $_SESSION upfront at the start of the application is giving those fields within the $_SESSION array a different set of properties from other fields which are added later. As a result, only those fields are surviving a generic loss across the page submit.
Option 2 seems like the only even potentially non-insane answer.
Does anyone know if that is even remotely possible?
Or alternatively what else could be happening?
i am using 1 index.php page and using navigation links to send values $_GET values which are used to retrieve page content from mysql database to effectively change the page which is working fine.
On one of the nav links a session variable is set when clicked which i want to use later, but when i click another nav link that doesnt set sessions the previously set session has been unset and so has no value. i have checked the session_id which is the same on each page and have checked that the session variable is actually being set by outputing to the screen, it just disappears when a new page is clicked.
Thanks
I think (but someone will correct if I am wrong) that you should start the session all over you website for the session to be kept in place. Try to add session_start(); at the top of all your pages and see if things improve. $_GET is not related to the session so it is unclear to me why you mention it...