Note, Session must start before header is sent. So you should try –
<?php
if( !session_id() ){
if( headers_sent() ){
die('headers already sent, cant start session');
}
else{
session_start();
}
}
// check existence, or not below 1
if( !isset($_SESSION['impression']) || $_SESSION['impression'] < 1 ){
$_SESSION['impression'] = 100;
}
// decrease the value by one
$_SESSION['impression']--;
// test
echo $_SESSION['impression'];
?>
Related Posts:
- How to display random users with avatars
- Session is not starting
- How to update BuddyPress xprofile fields programmatically? [closed]
- How can I add an image field to BuddyPress Extended Profile Fields? [closed]
- How to limit character length in BuddyPress function output [closed]
- How to set the default avatar of buddypress avatar [closed]
- Dequeue script to prevent javascript event conflict on wordpress child theme
- How to Extend login session times to a Month
- Hide tab Buddypress profile for visitors, not logged in users
- How do I pull avatar from post using BuddyPress? [closed]
- WordPress Website with Login system
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- Unhook the comment form in Buddypress
- How can i hide content if not friend in Buddypress? [closed]
- Order posts (across the whole site) by metadata date
- Disable visual editor on one specific page
- Can the wp-plugins (Must Use Plugins) URL be targeted for use in functions.php?
- In a WordPress plugin, how do you output HTML code inside the DOM header? [closed]
- Different ‘WP_CONTENT_URL’ for different subsites in Multisite setup?
- Linking thumbnail to full size image
- Removing Unnecessary Text from Admin Menu without CSS
- Display WordPress Search
- Preferred Use of home_url()?
- Functions.php reverted to new one
- Where does function_exists() look to decide whether a function exists? [closed]
- Get page slug and assign a variable within functions.php
- Clean-up script tags
- Make “sidebar template” the default template for new pages
- Refactor create_function
- Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]
- Attach parent category template to all subcategories
- How to insert a text in all pages and posts before or after specific places?
- Add class or ID to any WordPress function
- How to filter out shortcode when displaying the_excerpt() in the loop?
- Remove Font-Awesome MaxCDN Link & Load Locally
- How to remove howdy dropdown menu content
- Change Admin Bar “Visit Site” URL
- exclude a category from a search on a specific page
- Stop turning small dashes into longer ones
- How to get specified parent page title in my function
- Execute function after a post has been published
- Last updated date function
- Possible to display shortcode based on the category?
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- How to set default archive image without overriding first attached image? [closed]
- Toggle User Roles with button
- Passing a variable via wp_head and then calling it on the page
- Load Woocommerce and WordPress Functions Outside
- How to make custom column Admin>Users sortable?
- How to know which ajax file or function is called for action
- How to filter $content in shortcode function
- watermarking gallery items
- Difficulty with PHP function that displays a post’s format in WordPress
- WordPress Shortcode function display outside of widget
- Get rid of the widget Item Class=”widget-item”
- Storing password (functions.php)
- Change menu based on page template via functions.php
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Why is it so hard to add a class to the tag in the sidebar widget?
- Parent theme styles overriding child theme CSS [closed]
- Adding theme option values as custom body class
- How to add a new image size and apply it to posts only?
- What is the correct way to include my new functions and scripts in WordPress?
- Function to replace comment’s accented characters before posting
- wp_nav_menu work in functions.php but not in the theme
- Perform function on publish AND save (not just save)
- add_menu_page() with variable function
- include w_thumbnail_src in function?
- Multiple, Dynamic, Sidebars Problem – First Sidebar not working properly
- Custom blog post summary on blog index page
- Redirect to one of two pages after data submitted, depending on the current url
- Ajax Form Issues using Lightsail (AWS)
- Unable to login after registration
- Remove the ‘category’ url for one category type
- CSS style and app.js not loading
- blank page with wp_get_attachment
- Parent category as WOOCommerce Categories widget title
- Problem with my footer after changing WooCommerce Products Sorting [closed]
- Limiting WordPress Search function : Custom build
- Change user role based on total number of items ordered
- Function stops working
- Rewrite rules and the permalink
- Custom taxonomy check box now showing up
- Set display name from nickname with register process
- How to prevent multiple custom terms from being created
- revision id is one number behind – publish_post
- Limit Number of Posts on Blog Category Page Throwing 404 Error on Paginated Pages
- How to create a function to redirect a specified page to another page
- Multisite Admin Roles
- Database SQL Error, Should Work
- How To Get WordPress Categories Last Update Date?
- unregister_sidebar in child theme not working
- Print all inline styles to head
- Function to return custom post type titles from blog id 1
- How to request login for user but not for bots
- Call ACF data from functions.php [closed]
- Which template file to edit to edit homepage in Mystile [closed]
- Does functions.php apply to every page?
- Customizer cuistom CSS Priority ordre Issue
- WPDB query suddenly not working