Jump to content

$_GET and then keep that data in $_SESSION


dachshund

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

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.