Session variables unset between page content changes - php

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...

Related

How can I destroy specifics $_SESSION variables leaving page?

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();

Where do I end a PHP session so that a variable, created in the first PHP file, can be used in the second file?

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.

How to use session variables in wordpress

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.

PHP $_SESSION lost over several pages

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..

PHP SESSION variable get's deleted each reload

Does anybody know what can cause the $_SESSION variable to be cleared?
The session variable is used to keep track of products in the cart.
Everything worked perfect on the development and production server.
Out of a sudden the production server looses the session variable - without any changes updated. The production server is hosted with 1&1.
I added some debug information which prints the contents of GET, POST and SESSION.
Link to the website:
http://niehues-gmbh.de
Any cart button updates the SESSION variable
But any reload and other links delete the SESSION
I do call session_start() at the beginning of index.php which loads all other contents.
Be careful of tabs. If someone loads product detail in another tab, the browser sees it as a reload or link, and as you said, session is cleared at these times. It's better to store your cart in the database.
I fixed the issue by keeping the HTML / PHP standard.
If I remember right then there were white spaces before a header function which made the page not work correctly.

Categories