I'm trying to work with sessions using wordpress ajax call api, but unsuccessfully.

In begining of functions.php writed:

if (!session_id()) {

When doing ajax call for example to function

add_action( 'wp_ajax_nopriv_compare_objects_request', 'compare_objects_request' );

Session in 'compare_objects_request' function is not available.

Besides, when in function 'compare_objects_request' putting session_start(), then every time when call is fired, $_SESSION variable is always new set.

1 Answer 1


WordPress does not use or affect PHP Sessions in any way. Therefore, the session functions will work exactly the same whether you're using WordPress or plain PHP or AJAX requests or anything else.

However, PHP Sessions depend very heavily on your specific PHP configuration. If you don't have the PHP Session settings configured correctly in the PHP.INI, then they tend to not work properly. And a lot of web hosts don't have properly configured defaults for sessions. Therefore, PHP sessions are not safe to use unless you have control over the configuration of the server, and are not suitable for distributed code because a lot of hosts don't have good configurations.

So, make sure you have the setting settings set up correctly in PHP before trying to use them.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.