Omzy Posted October 12, 2009 Share Posted October 12, 2009 cart.php: echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'; foreach($_SESSION as $index => $value) { echo '<input type="hidden" name="'.$index.'" value="'.$value.'" />'; } echo '<input type="submit" value="Checkout Now" /></form>'; I want the $_SESSION to be emptied/destroyed once the form has been submitted. Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 Check out example 1 of the session_destroy function. Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 12, 2009 Author Share Posted October 12, 2009 OK but I only want the session to be destroyed IF the form is submitted by the user, not when it is displayed. Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 if(isset($_POST['submit'])) { Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 12, 2009 Author Share Posted October 12, 2009 Will that work though? Because the form will have been submitted to a different page. Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 Then no it won't, but the theory is the same regardless. You need to track whether the form is submitted, so you must have a value somewhere, be it in the $_SESSION or wherever, simply check that value then destroy the session. Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 12, 2009 Author Share Posted October 12, 2009 "You need to track whether the form is submitted" Well this is it you see, how would I do that if the form is going to a different page? Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 Your going to have to be more specific about your problem otherwise we're going to be going around in circles. Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 12, 2009 Author Share Posted October 12, 2009 It's pretty much straightforward I would have thought? cart.php is a shopping cart, as the filename would suggest. When the user is happy with the contents of the cart they can hit "Checkout Now" which is a submit button linked to a form which posts the SESSION variables to PayPal. The PayPal screen opens in the same window. All I want is for the SESSION to be destroyed if the user submits the form. If they don't submit the form then everything stays as it is! Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 I've never done any PayPal integration, but I assume at some point it sends information back to your application, otherwise how would you know the transaction was succesfull? Empty the Session then. Quote Link to comment Share on other sites More sharing options...
Omzy Posted October 12, 2009 Author Share Posted October 12, 2009 Well this is it - I'm not doing a "full" integration - PayPal does indeed send back notifications but it's a b*tch to implement and not worth the hassle when all I want to do is clear the session! That's why I'm trying to do it the easy way - but evidently it does not seem to be any easier! Quote Link to comment Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 No, it's not. The only work around I can think of would be to POST to a page of your own, on that page use cURL to submit the information to PayPal, then reset your Session. But I suspect that will be no easier that using 'proper' integration. 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.