Jump to content

Error and success messages stored in SESSION


jacob21

Recommended Posts

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 giftCards
REDEEM BUTTON
.................

<?php
$action = '<input type="button" value="Redeem" onclick="location.href=\'index.php?do=giftCards&action=redeemGiftCard&id='.$row['id'].'&currency='.$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 //
	
}
?>

.................

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.