Jump to content

[SOLVED] Sending Variables through a header redirect


Recommended Posts

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!

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

 

 

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.

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.