I currently have a WP website that implements a PayPal integration using PHP (this is an old project I am going back to after several years away, too much time on my hands).
Current versions WordPress 5.4.1 PHP 7.1 (host providers limitations, not mine)
In the old version logged in users have access to the PayPal button, once payment is complete they were returned to a custom url (needed). During the payment process, on successful payment, I create a $_SESSION['fromProcess'] = "true"; and header('Location: customurl').
On the custom url page I check to see where the user came from and if the session is set
if ( is_user_logged_in() ) {
// logged in
if($_SESSION['fromProcess'] == "false"){
//send them back
header("Location: https://example.com/error-page/");
}
else{
//reset the variable
$_SESSION['fromProcess'] = "false";
}
$uid = $_SESSION['uid'];
$txn = $_SESSION['token'];
if( (!isset($_SESSION['uid'])) && (!isset($_SESSION['token'])) ){
header('Location: https://example.com/error-page/') ;
//stop executing the script
exit();
}
}
This seemed to work perfectly fine in the older version, but not in the newer WP,PHP versions.
Is there any way to make this work or do I need to be looking at a different approach?
Thanks