Canman2005 Posted December 20, 2009 Share Posted December 20, 2009 Hi all I have a simple shopping cart which when you add an item to the cart, the following code is run; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_REQUEST['id']; header("Location: cart.html"); exit; } else { $cart = $_REQUEST['id']; header("Location: cart.html"); exit; } break; this has worked fine on my local web server, but when I upload it to the website server I run into some issues. Firstly the above code doesn't work and no items are added, but if I remove header("Location: cart.html"); exit; then the code does run ok, the problem is that if it doesn't do a "header("Location")" then I still have ?action=add&id=2 showing in the URL, therefore if the page is reloaded, the quantity of that item increases by 1. Does anyone know why a header("Location: cart.html"); is stopping? One thing I did notice was that "register_globals" is turned off, I found if I add register_globals = on to a php.ini file, the site runs fine. Can anyone help? Thanks Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted December 20, 2009 Share Posted December 20, 2009 Never use register globals if your not sure about the security issues involved therein; This part of your code: switch ($action) im guessing should be switch ($_GET['action']) hope this helps, -CB- Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted December 20, 2009 Author Share Posted December 20, 2009 Hi Nope, that didn't seem to fix the issue, still does what it did before. Any other advice I can try? Thanks Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted December 20, 2009 Share Posted December 20, 2009 Hmm, that code should run fine and register globals shouldn't affect it. Try some debugging; do this before the switch : print_r($_GET); print_r($_POST); try the header() function before the switch to see if the header function actually works at all. Any other ways you can think of debugging try also and give us your results. -CB- Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted December 20, 2009 Author Share Posted December 20, 2009 Thanks guys, code was in wrong place, works fine now, thanks again Quote Link to comment 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.