jacob21 Posted December 8, 2014 Share Posted December 8, 2014 Is it a good practice to store error and success messages in SESSION? Folder pages/giftCards ->index.php ->viewGiftCardCodes.php ->redeemGiftCard.php ->giftCards.php index.php <?php if(defined('script') === FALSE){ exit('Hacking attempt...'); } if(loginCheck($userInfo) === FALSE){ redirect('index.php?do=login&returnUrl='.$_SERVER['REQUEST_URI'], FALSE, TRUE); } if($configs['giftCardEnabled'] == 'no'){ alert('This page is currently disabled.', 'index.php?do=home'); } $action = isset($_GET['action']) ? $_GET['action'] : ''; switch($action){ case 'redeemGiftCard'; include 'pages/giftCards/redeemGiftCard.php'; break; case 'viewGiftCardCodes'; include 'pages/giftCards/viewGiftCardCodes.php'; break; default: include 'pages/giftCards/giftCards.php'; break; } ?> Default action giftCardsREDEEM BUTTON................. <?php $action = '<input type="button" value="Redeem" onclick="location.href=\'index.php?do=giftCards&action=redeemGiftCard&id='.$row['id'].'¤cy='.$row['currency'].'&amount='.$row['amount'].'&csrfKey='.$csrf->csrfKey().'&csrfToken='.$csrf->csrfToken().'\'">'; ?> .................Action redeemGiftCard.................If success <?php $_SESSION['message']['1'] = 'You have successfully redeemed a gift card worth '.$row['currency'].$row['amount'].''; redirect('index.php?do=testPage1', FALSE, TRUE);// Page, Refresh, Exit // ?> If error <?php $_SESSION['message']['2'] = 'Database error. Please try again later!'; redirect('index.php?do=testPage1', FALSE, TRUE);// Page, Refresh, Exit // ?> .................Default action giftCards................. <?php if(!empty($_SESSION['message']['1'])){ $success = $_SESSION['message']['1']; unset($_SESSION['message']); } if(!empty($_SESSION['message']['2'])){ $error = $_SESSION['message']['2']; unset($_SESSION['message']); } if(!empty($success)){ print success($success);// HTML and success var // } if(!empty($error)){ print error($error);// HTML and error var // } ?> ................. Quote Link to comment https://forums.phpfreaks.com/topic/292970-error-and-success-messages-stored-in-session/ Share on other sites More sharing options...
CroNiX Posted December 8, 2014 Share Posted December 8, 2014 Yes, that's appropriate especially if you are redirecting. Quote Link to comment https://forums.phpfreaks.com/topic/292970-error-and-success-messages-stored-in-session/#findComment-1499022 Share on other sites More sharing options...
CroNiX Posted December 8, 2014 Share Posted December 8, 2014 however, I don't see you using session_start() at the beginning of any of those pages Quote Link to comment https://forums.phpfreaks.com/topic/292970-error-and-success-messages-stored-in-session/#findComment-1499036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.