tidysi Posted August 28, 2007 Share Posted August 28, 2007 My ecommerce system requires that certain variables be passed to it in POST form - normally i would submit directly from a form and it would be fine; my problem is that I need to do some validation first on this form and then insert the variables into the header("Location: URL ") from variables in the php script So essentially: confirmationPage.php -------------------- <form id = "frmConfirmation" name = "confirmOrder" action="confirmationPage.php" method="POST" onSubmit="return validate_frmConfirmation(this);"> // form elements <input type="hidden" name = "ticketDate"/> <input type="hidden" name = "numDayAdults"/> <input type="hidden" name = "numDayChildren"/> </form> The javascript validation works fine. When the form is submitted I need to check the ticketDate variable in PHP before submitting it to the ecommerce site; how do i put these variables into the header('Location: ') function? Any suggestions would be absolutely brilliant because this has been bugging me for a while now! Thankyou! Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/ Share on other sites More sharing options...
php_tom Posted August 28, 2007 Share Posted August 28, 2007 First of all, I'd do the data validation server-side in PHP, not client-side in JS... its more secure that way. But your real question: header("Location: myPage.php?date=".$_POST['ticketDate']); Maybe that helps? Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/#findComment-336557 Share on other sites More sharing options...
tidysi Posted August 28, 2007 Author Share Posted August 28, 2007 Sorry No that doesn't work - Does using the header('Location') function send the variables you add to it as a POST or GET ? The ecommerce transcation system that i am pointing to wants them in the POST format - when i try it, it all looks fine in the address bar but the transaction script doesn't pick it up? Any Ideas? I'm pretty sure that this is the sticking point Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/#findComment-336567 Share on other sites More sharing options...
lightningstrike Posted August 28, 2007 Share Posted August 28, 2007 php.net/curl Read more about the cURL extension. After the user confirms the data. Simply POST the data to the e-commerce programs script. If that is not possible you could show the user a form and use javascript to auto-submit it. Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/#findComment-336572 Share on other sites More sharing options...
php_tom Posted August 28, 2007 Share Posted August 28, 2007 anything like stuf.php?variable=moreStuf is GET. But you can get either through $_REQUEST. If they want it in POST, you can instead of using header(), maybe this: <html> <body onload="document.getElementById('form1').submit();"> <form action='page.php' method='POST' id='form1'> <input type='hidden' name='ticketDate' value='<?php echo $_POST['ticketDate']; ?>' /> </form> </body> </html> Of course this only works if the client has JS, otherwise they see a blank page. And it's less secure, usually you don't put important stuff in hidden fields. I guess you could also pass info from page to page with sessions or cookies but then it gets more complicated. Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/#findComment-336573 Share on other sites More sharing options...
tidysi Posted August 28, 2007 Author Share Posted August 28, 2007 Thanks everyone for the help I've been scouring the internet about curl since that seems to be what I want: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"example_transactionURL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "VPSProtocol=2.22"); curl_exec ($ch); curl_close ($ch); exit; This fixes the problem however introduces a new one that I hope you can help with When I run this, rather than going to the 'example_transactionURL', the script seems to send the data to it and stay on the same page that i called the script for - yet I can still see some output from the target URL. What I really want is for the the browser to be at the new URL rather than the old one. Is this making sense- I think I'm almost there - is it another curl_setopt for this ? Thankyou! Quote Link to comment https://forums.phpfreaks.com/topic/67107-solved-sending-variables-through-a-header-redirect/#findComment-336604 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.