I am new to write a plugin ..I am having a testplugin.php file and a ajax.php file ..
My code in testplugin.php is
global $session;
print_r($abc);
In my case I was using that session variable in plugin activation as well. So did something unorthodox. Instead of defining my session_start in a hook I made it as the first line in my plugin :).
To heck with plugins, as soon as wordpress scans through my file it initiates the session.
At the end I do not destroy the session on user logout. I simply unset my variable. This is to just in case if some other plugin is also using session. If I destroy session it may affect other plugins.
Cheers.
// On your plugin or themes functions.php
function register_session(){
if( !session_id() )
session_start();
}
add_action('init','register_session');
// To set a SESSION
data -
$_SESSION['arrayImg'] = $abc;
// To get the data on ajax hooked function -
function resolve_the_ajax_request(){
if( !session_id())
session_start();
$abc = $_SESSION['arrayImg'];
}