Wordpress problems
I found a bunch of articles talking about using sessions. From what I have found in the best possible way, add an init action. I am following this article http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/
but I must be missing something. every time i call the page with my plugin there is no session id
Did I miss something?
thanks for any help
add_action('init', 'my_GB_StartSession', 1);
add_action('wp_logout', 'my_GB_myEndSession');
add_action('wp_login', 'my_GB_myEndSession');
if (!function_exists('my_GB_StartSession')) {
function my_GB_StartSession() {
if(!session_id()) {
errorLog("session starting\n");
session_start();
}
}
}
function UnitNet_GB_myEndSession() {
session_destroy ();
}
+3
source to share
1 answer
try this and add function.php to your theme:
add_action('init', 'myStartSession', 1);
add_action('wp_logout', 'myEndSession');
add_action('wp_login', 'myEndSession');
function myStartSession() {
if(!session_id()) {
session_start();
}
}
function myEndSession() {
session_destroy ();
}
Now the session will be used by you as you wish in the code:
$_SESSION['myKey'] = "Some data I need later";
if(isset($_SESSION['myKey'])) {
$value = $_SESSION['myKey'];
} else {
$value = '';
}
Or add this to wp-config.php before wp settings (like at the top of wp-config.php)
if (!session_id())
session_start();
0
source to share