Jump to content

Form submission (no button) using PHP+cURL+ transfer control to other site


jsherk

Recommended Posts

I've spent HOURS searching the net for answer to this, but can't find it...

 

I'm trying to send data using the POST method and also have control of the browser be turned over to the website that's receiving the POST data (note that this is NOT the same as sending the data via POST method and then redirecting to the website after). I need it to work exactly like hitting the submit button on an html form, and I need it to work from PHP. It needs to POST the data to the site and also let the other site have control at the same time.

 

I've tried a couple of methods using both cURL and an fsocket function, but it seems like in both cases that (1) the data gets sent to the other site first, (2) then my program gets a response back, (3) and then it redirects to the other site afterwards. The data gets sort of POSTed to the other site (I get a 200 response back, and I get info showing it was posted correctly), but since the other site does not get control, it seems to dump (not save) the posted data.

 

Here's my cURL example:

<?php
    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $url = 'https://www.xyz.com/xyz.exe/xyz-AddItem';
    $part1 = 'SB123';
    $item1 = 'blue socks';
    $qty1 = '1';
    $price1 = 5;
    $dat = "PartNo=".$part1."&Item=".$item1."&Qty=".$qty1."&price=".$price1."&";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$dat);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  1);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
    $result=curl_exec ($ch);
    curl_close ($ch);
    echo("Results: <br>".$result);
?>

 

Somehow I think it needs to redirect (hand over control) exactly when the curl_exec function is called, because this is when the data would be POSTed.

 

Is there a way to terminate my php program AND hand the browser over to this other site AND pass the data over using the POST method, all at the exact same time?

 

I tried:

header ("Location: https://www.othersite.com);
exit();

 

But this also seems to POST the data first, and then redirects to the other site after, which has the same effect of my POSTed data being dumped.

 

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

  • 3 months later...
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.