I`m currently developing WordPress plugins on several servers and I noticed that on some configurations you can`t use $_SESSIONS in your plugins, so I though it will be a good part of our wordpress tutorials section to write about fixing this problem. The SESSION gets killed or it is just not starting. So I started digging through the core to find a solution and guess what I finally did. The problem is related to php.ini. If register_globals = On in php configuration file you have to comment “wp_unregister_GLOBALS();” in wp-settings.php
The WordPress Codex clearly states that if “register_globals=On”, “wp_unregister_GLOBALS()” will destroy php sessions.
To enable php sessions edit wp-settings.php (In your wordpress root), and comment wp_unregister_GLOBALS() on Line:40 after that your code should look like this:
<?php /** * Used to set up and fix common variables and include * the WordPress procedural and class library. * * Allows for some configuration in wp-config.php (see default-constants.php) * * @internal This file must be parsable by PHP4. * * @package WordPress */ /** * Stores the location of the WordPress directory of functions, classes, and core content. * * @since 1.0.0 */ define( 'WPINC', 'wp-includes' ); // Include files required for initialization. require( ABSPATH . WPINC . '/load.php' ); require( ABSPATH . WPINC . '/default-constants.php' ); require( ABSPATH . WPINC . '/version.php' ); require( ABSPATH . WPINC . '/extra_function.php' ); // Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE. wp_initial_constants( ); // Check for the required PHP version and for the MySQL extension or a database drop-in. wp_check_php_mysql_versions(); // Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php. @ini_set( 'magic_quotes_runtime', 0 ); @ini_set( 'magic_quotes_sybase', 0 ); // Set default timezone in PHP 5. if ( function_exists( 'date_default_timezone_set' ) ) date_default_timezone_set( 'UTC' ); // Turn register_globals off. //wp_unregister_GLOBALS(); ... ...