Session is not working properly

Any caching solution will probably break sessions.

Try turning off all caching (as well as CloudFlare proxy for your IP address) and see if your code works. If you have a WordPress caching plugin – turn that off too. If your hosting provider does some caching – turn that off too.

After turning off all caching if your site works, then you’ll have to either 1) find another solution not using PHP sessions (recommended), or 2) make sure you never cache your pages (not recommended).