PHP SESSION variable get's deleted each reload - php

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.

Related

$_SESSION values lost when pressing browser back button, perfectly there when reloading the page

Alright so this explanation might be a little... wonky?
So to break it down imagine this scenario
I add information to the $_SESSION using a button on Page A this all goes fine. I click to go to Page B, everything is still fine and the $_SESSION values are all there. But when I go back to the previous Page A using the browsers back button my added value is not there for some reason.
I am trying to find out why this happens and if I can prevent it from happening, because if I reload the page again with F5 the information is there no problems whatsoever.
Thanks already.
You should start session in each of your PHP pages ;
session_start();

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.

Unwanted independent sessions for two separate pages

I am stumped. Everybody says if you use session_start that you should get a single session even when you open multiple browser windows. However, it seems that my sessions are page specific.
When I load page one (index.php), it gives as a Session ID: sr51j9hhrjjrvbrfboek15l4e4 with an empty $_SESSION array
I then log in on a webpage (login.php) that generates a new Session ID: v2t8844nglg7uvnsrbr6k9ms43 with a $_SESSION array with various variables.
When I then reload page one, it will display the old session ID, not the new one as expected. It is page linked because if I copy load page two in tab one, it will give the same session ID as the page in tab 2, and visa versa.
I have added the rule
CacheDisable /local_files
to the httpd.conf file with no effect.
I uses Apache 2.4 (XAMPP installation for windows), with the http://php-login.net advanced login script.
Top of page (before the HTML tag):
session_start();
require_once('includes/connection.php');
followed by:
echo var_dump($_SESSION);
echo session_save_path();
echo 'Session ID: '.session_id();
at the top of the page in the body tag.
Any suggestions?
session_start() will create a single session that can be used across the same browser/tabs.
Okay, found the answer here: My session ID's stopped working
One page was localhost:8001, while the second was 127.0.0.1:8001, which are treated by the server as two separate pages for the purpose of sessions, while serving the same page.

Wordpress - SESSION variable does not last

I've spent some time researching answers on this problem, but neither have resulted in fixing my issue. I attempted to make use of the $_SESSION variable. On the first page, I put the result of a input form entry (a name) into it, as it will be used across a variable number of pages. On the page after, the session variable seems to be working fine. I used a var_dump to debug it and everything seems to be set well. Then I click the link I created to go to the next page in this chain of linking. I assume that because the session is being saved, the variable will last until the user exits the website or browser.
Suddenly, on this second page, the session variable becomes null again.
I did a temporary fix where I just pass the GET value from the first page and plug it into the link page links url through some php. It works as intended, but will love to be able to make sessions work when I get to more complicated problems.

Session variables unset between page content changes

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

Categories