mo Posted March 6, 2009 Share Posted March 6, 2009 I have a list of menu items than a user can click on. The link for each menu item passes the $_GET variables to the next page which is used for adding the items to the cart, etc. My links are as follows: <td><a href=\"menuitm.php?ID=$Item&price=$Price&name=$strName&store=$StoreName&sid=$StoreID\">$strName</a></td> I use $_GET on the menuitm.php page and everything works fine, but a user could change the data in the URL, hit enter and have the $_GET variables reflect tha change. This means they could change the price and cheat the cart. I wanted to use a session variable but each row has a link, so I would have to do something like fill the session variable on-click of the link. I tried the following base64_url_encode and base64_url_decode, but I am unsure how to use the decrypted string on the next page to get the $_GET variables. Functions: function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } Link to comment https://forums.phpfreaks.com/topic/148233-encryptdecrypt-url-base64_url_encode/ Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi I take it you want to prevent people changing the query string. What you could do it take your current query string, add something random to it and md5 hash it. Then add that as an extra field on the query string. When you process the form take the query string, chop off the md5 hash part and redo the md5 hash. Then compare the one you have now created with the one passed back on the query string. If they do not match then someone has been playing. However I would also say that you should not put sensitive info (like the price) where a user can easily change it. Just work off the item id and pull the price back from the database when you process the data they have entered. All the best Keith Link to comment https://forums.phpfreaks.com/topic/148233-encryptdecrypt-url-base64_url_encode/#findComment-778186 Share on other sites More sharing options...
mo Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks. Your correct. I was trying to avoid hitting the database again as I want my site to be as efficient as possible, but I will just get the price from the DB on the next page. Link to comment https://forums.phpfreaks.com/topic/148233-encryptdecrypt-url-base64_url_encode/#findComment-778191 Share on other sites More sharing options...
mo Posted March 6, 2009 Author Share Posted March 6, 2009 I actually just used base64_url_encode and base64_url_decode anyway so as to not hit the DB on the next page. I use base64_url_encode("<url>") and on the next page I do the following. $DecodedUrl = base64_url_decode(getFullUrl()); parse_str($DecodedUrl, $UrlArray); $_GET['name'] = $UrlArray['name']; $_GET['price'] = $UrlArray['price']; $_GET['smid'] = $UrlArray['ID']; $_GET['store'] = $UrlArray['store']; Does this look OK? It works fine and I know it can still be decoded by someone if they wanted to but what I decided to do is a check of the item on check out to see if the price in the cart matches what is in the DB. Link to comment https://forums.phpfreaks.com/topic/148233-encryptdecrypt-url-base64_url_encode/#findComment-778225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.