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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/ 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935371 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935372 Share on other sites More sharing options...
cags Posted October 12, 2009 Share Posted October 12, 2009 if(isset($_POST['submit'])) { Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935374 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935378 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935381 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? Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935390 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935395 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! Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935398 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935401 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! Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935404 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. Link to comment https://forums.phpfreaks.com/topic/177400-solved-post-a-form-and-empty-the-session/#findComment-935409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.