dachshund Posted December 19, 2011 Share Posted December 19, 2011 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/253500-_get-and-then-keep-that-data-in-_session/ Share on other sites More sharing options...
KevinM1 Posted December 19, 2011 Share Posted December 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253500-_get-and-then-keep-that-data-in-_session/#findComment-1299469 Share on other sites More sharing options...
dachshund Posted December 19, 2011 Author Share Posted December 19, 2011 Cool - cheers! Quote Link to comment https://forums.phpfreaks.com/topic/253500-_get-and-then-keep-that-data-in-_session/#findComment-1299471 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.