Hi iam new to wordpress and I have created a plugin at which I need to print all the session data.First I have created a file in plugin folder and added code like
function myplugin_classname() {
print_r($_SESSION);
}
And I put an click event for two button with class tags
like
$('.tags').on('click',function(){
$.post('my_page.php',{val:$(this).val()});
});
and in my_page.php I kept like
$_SESSION['tag'] = $_POST['val'];
but when it comes to printing the session variables at myplugin_classname
(by refreshing the page)it doesnt prints the newly assigned session variable....How to solve this..??I have started session through theme-my-login
login.
The simplest way to get access to the session is to add the following lines to wp-config. php before the call to wp-settings: if (! session_id()) session_start();
WordPress Core does not use sessions. All "user state" is managed via cookies. This is a Core design decision. However, some plugins or themes will use session_start() or PHP's $_SESSION superglobal.
From your WordPress dashboardVisit 'Plugins > Add New'. Search for 'Sessions'. Click on the 'Install Now' button. Activate Sessions.
By default, session data is stored in the server's /tmp directory in files that are named sess_ followed by a unique alphanumeric string (the session identifier).
You need to add <?php session_start(); ?>
at beginning of my_page.php
After that for destroying session you can use wp_logout action in wordpress. code is as follows
<?php function custom_unset_session() {
// your code
unset($_SESSION['tag']);
}
add_action('wp_logout', 'custom_unset_session');
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With