ok this is desperation, I have tried every fix I can find but with no luck.
I am using session variables in wordpress and it works fine in every browser except for Firefox. I have cleared the cache, cookies, started in safe mode etc but no joy. Cookies are enabled and I have also tried it on different pc’s.
I start the session in my theme functions file as follows:
function myStartSession() {
if(!session_id()) {
session_start();
}
}
add_action('init', 'myStartSession', 1);
Then on my individual page templates I create the session variable as follows:
$_SESSION[‘hq’] = 1;
I can confirm that the sessionid remains unchanged in every browser and is working correctly including Firefox, however in FF the session variable is not correctly passed from one page to another and the results are unpredictable.
Any solutions / recommendations are very welcome.
Not a brand new question, but since I was looking for a solution and got here, I’ll answer it to maybe help other programmers.
I had a similar problem with a WordPress theme that I developed and I found a solution in this post at StackExchange: https://wordpress.stackexchange.com/questions/40271/2-different-post-ids-for-single-page-load-only-in-firefox
Due to Firefox’s prefetch, the next post/page is loaded in background and session is affected by this behavior.
There is at least two possible solutions to fix this:
Remove the action that inserts the next page/post in page
<head>
with the following function call:It can be added to your theme’s
functions.php
file.Check the request headers to handle (or maybe ignore) prefetching. All prefetching requests are sent to the server with a special header, as follows:
You can look for this header and treat the request in a distinct way.