Jump to content

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 //
	
}
?>

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.