Jump to content

Recommended Posts

I'm trying to add voucher codes to my shopping basket. When someone submits a voucher code it adds ?vouchercode=WHATEVERTHECODE to the URL.

 

I then $_GET this data and store is as $_SESSION['vouchercode']. The problem is, on the next page it $_GET's the ?vouchercode again, which is this time blank, and sets the session to blank as well.

 

Any help?

 

Here's my code:

 

$vouchercode = $_GET['vouchercode'];
$_SESSION['vouchercode'] = $vouchercode;
if ($rows['brand'] == 'Dank' AND $_SESSION['vouchercode'] == 'DANKINT')	{
echo 'Voucher Code DANKINT Used';
}

You need to check to see if the voucher code exists before using it:

 

if (isset($_GET['vouchercode']))
{
   $_SESSION['vouchercode'] = $_GET['vouchercode']; // <-- you should validate and sanitize this before using it, but that's another topic
   
   // continue with voucher code stuff
}

// continue with non-voucher dependent code

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.