Redirect to another site with POST data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the_lar
Forum Newbie
Posts: 4
Joined: Mon Aug 21, 2006 9:55 am

Redirect to another site with POST data

Post by the_lar »

Hi All,

I'm looking for a neat solution to a problem.

My site processes payments (via paypal DirectPay) and on success I want to redirect the user to another site and include some POST data which is a reference number.

If I use header("location: http://redirectionsite.com) I believe I can only send GET variables on the request URI. This has to be POST. I've looked at using CURL but it seems that it doesn't actually redirect, it kind of pulls the redirection site into the page on which the curl_exec command is executed. I may be mistaken because I'm pretty much a newbie with CURL stuff.

This seems like it should be pretty simple but I can't figure it out I'm afraid - any help would be great.

Many thanks
Kevin
aneesme
Forum Newbie
Posts: 9
Joined: Wed Jan 27, 2010 4:22 am
Location: Bangalore

Re: Redirect to another site with POST data

Post by aneesme »

Code: Select all

<script type="text/javascript">
function postData () {
    var daForm = document.createElement("form");
    daForm.method = "post" ;
    daForm.action = "http://google.com" ;
    var firstVal = document.createElement("input") ;
    firstVal.setAttribute("name", "q") ;
    firstVal.setAttribute("value", "Search String");
    daForm.appendChild(firstVal) ;
    document.body.appendChild(daForm) ;
    daForm.submit() ;
}
window.onload = postData; 
</script>
Hope it helps.
Post Reply