'Session destroy after redirect from payment gateway in codeigniter 3

When payment gateway like payumoney, ccavenue, paytm etc. redirect to callback url or redirect url or you can say that after payment success or failure we are able to collect data from gateway but unfortunately session destroy automatically sometimes. Sometimes i am able to collect session data and sometimes it destroy all the session data. As i check, session actually not destroy but it creates a new session file or regenerate a session id. There no white space, no special characters also i have tried to store session in database but not helpful.

Also changed the system/libraries/session/session.php

i have also tried this session destroying in codeigniter after redirecting



Solution 1:[1]

This issue is related to the SameSite Cookie Policy (Browser Policy), this is not related to payment gateway.

Please follow below step to fix it.

Use Cookie with SameSite None - https://github.com/GoogleChromeLabs/samesite-examples/blob/master/php.md

OR

add below in .Htaccess (It can be help

Header always edit Set-Cookie (.*) "$1; SameSite=None"

Solution 2:[2]

Add these lines to your code

ini_set('session.cookie_samesite', 'None');
ini_set('session.cookie_secure', true); 

Comment below line if you have in your code

ini_set('session.use_strict_mode', 1);

This solution worked for me in core PHP try this in CodeIgniter and check if it works

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ravindra malviya
Solution 2 ChrisMM