Are you doing this in a plugin or on a template file?
Also, you certainly want to ensure that you’re properly setting up sessions. I recommend doing so in functions.php. e.g:
add_action('init', 'track_sessions', 1);
function track_sessions() { // if session isn't active, set it
if(!session_id()) {
session_start();
}
}
And using them as you are:
$_SESSION['my_val'] = $val;
Once done, you need to destroy the session:
add_action( 'your_action_here', 'destroy_session', 10, 5 );
// All done. Destroy session
function destroy_session() {
session_destroy();
}
Related Posts:
- Display message once per session to users with a specific role
- How to log out everywhere else, destroy all sessions “all other devices”?
- Why does $_SESSION only work when I am logged in?
- how to create and show sessions in word press?
- Should I store my Facebook access tokens?
- Site Health : An active PHP session was detected
- integrating external php library into wordpress- the right way
- How to expire session after 2 hours and also expire when browser closed?
- Fatal Error relating to sessions.php
- How to store post ID’s in cookie or session to display the same posts later
- iframe does not store session/cookie when refresh parent
- Unique session WordPress
- Get my site session in wordpress?
- Having Issue on Redirecting With Session in WordPress
- Unset session variable on page reload / setup but exclude AJAX
- $_SESSION variable not saving on page refresh or new page
- $_SESSION variables work perfectly on my local machine but returns NULL on development webserver
- Custom $_SESSION expires too early
- Can we stop session reset if page reloads?
- Store and Change Session variable – PHP SESSION VARIABLE
- Deleting expired session tokens in WordPress
- PHP: $_SESSION destroyed after page reload for my custom session
- Set cookie parameters on wp site – PHP not working?
- Are there any drawbacks on opening a session_start in functions.php and header.php?
- Like and Dislike Buttons on Post with Counter – Only allow one click per post per user session
- PHP session not staying alive. headers already sent
- Sessions with WordPress
- Use WP user status (logged_in) to manage access to independent application
- ajax polling with admin-ajax.php
- PHP Session Variable to WordPress Error
- Allow user to select location and then set cookie for location in WordPress
- How to ‘remember’ a site member’s last visited page?
- White screen after login attempt
- Where are Sessions are being started? [closed]
- WordPress & PHP sessions
- How to transfer session after being redirected to other page
- Suddenly sessions and header location not working
- PHP – Having $_SESSION as an array and adding $_SESSION to array
- How to create custom 401, 403 and 500 error pages?
- add_action in namespace not working
- Variables declared in header not available in other includes
- Failed to open stream / no such file or directory
- Need to get specific data from array
- Use different javascript files for each page on website
- WooCommerce – Fixed quantity of a product [closed]
- Settings API – sanitize_callback is not called and it leads to an incorrect behavior
- Function set default image when image not present
- How to get the POST TITLE using the POST ID?
- Importing hard coded custom field into acf field
- From where the header-text can be changed in WordPress custom header?
- Trying to establish connection to External Database
- Load a page into a div with Ajax
- Login/logout in header
- $wpdb->update with multiple parameters gives error
- Improve page speed loading using CDN and async or defer attribute
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Dashboard broken into list of links
- My custom get_the_excerpt() can’t get excerpt by ID
- deactivating an active plugin using if page
- Single Quotes in .php file doesn’t load website
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- {$key} or $key?
- Display the 3 latest WordPress Posts on a Static Page Outside WordPress
- Shortcode to pull posts
- PHP Strict Standards: Only variables should be assigned by reference
- url_to_postid returns 0
- How to Fix an Archive.php That Displays All Posts?
- Dynamically replicate custom metabox in custom post type
- How to tell if a user has gone in and created a menu
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- WordPress Fresh Install Errors (Woocommerce specifically now)
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- php script in elementor
- how do i add custom widget woocommerce shop page with php
- WordPress redirect to a subpage – how to create a template for subpage?
- How can I redefine WordPress wp-content directory programmatically?
- Trim Titles Only On Some Pages
- Automatic email message after manual user approval
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- Enqueue sripts and styles only if function is called
- Return author name as a tag using get_author
- How to pull date/time in french format for wordpress post?
- WooCommerce subcategories help
- What is wrong with this shortcode? to include external php file in WordPress posts
- Migrating a live WordPress website to a Local Server: why some elements of the website are missing?
- Store stripe info as user_meta
- Is there a way to have chunks of a page’s content expire?
- Loop returns more items than exist?
- Formatting Shortcode to Display in Visual Mode
- Rewriting to a different page based on existence of query string?
- Host does not allow remote connection, so how do I transfer data to my WordPress site?
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How to call a specific value within the functions.php file?
- WordPress plugin/code to to to next/previous post in same category
- How to use js variable to php in wordpress functions.php
- Display total count of products in orders of a specific order status
- inner-wrap div pushing custom table far down on page
- Remove Woocommerce product from cart with ajax/fetch
- How to edit a widget code?
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?