Problem : Wordpress session variable not working
I have an issue with a WordPress session.
In the file themes/theme-name/header.php I wrote this code:
session_start(); if(isset($_SESSION['var'])) { echo 'Welcome'; } else if(isset($_POST['var'])) { $_SESSION['var'] = $_POST['var']; } else { echo 'No access...'; exit; }
Solution For : Wordpress session variable not working
Just hook a function on "init" in your functions.php like this :
function ur_theme_start_session() { if (!session_id()) session_start(); } add_action("init", "ur_theme_start_session", 1);
Then we can use our session variables.
I hope that help you.
No comments:
Post a Comment