tags:

views:

521

answers:

2

Hi Guys,

I am in a bit of a rut with a cURL issue. The post works greate, the data is POSTED just fine and received ok, but the url of the posted page never appears in the browser after the cURL session is executed, for example look at the following code:

    $ch = curl_init("http://localhost/eterniti/cart-step-1.php");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "error=1&em=$em&fname=$fname&lname=$lname&email1=$email1&email2=$email2&code=$code&area=$area&number=$num&mobile=$mobile&address1=$address1&address2=$address2&address3=$address3&suburb=$suburb&postcode=$postcode&country=$country");
    curl_exec($ch);
    curl_close($ch);

The post works fine and I am taken to the cart-step-1.php where I can process the posted data, HOWEVER the location in the URL address bar of the browser remains that of the script page, in this case proc_xxxxxx.php

Any ideas how to get the URL address to reflect the page I am actually POSTED to?

Thanks a mill

A: 

in that case you'll need to do it in html - so your proc_xxxxxx.php returns an html page that contanis a form that actually sends the post data.

what you're currently doing is retrieving a certain page (with parameters) on your server and returning that as the data for the page that the browser requested. your browser still thinks it called proc_xxxxxx.php but the html data it gets back from the server is that from the cart-step-1.php request, but your browser has no way of knowing this.

setting the url in the browser bar to something arbitrary is impossible as it would be an enormous security risk (eg window.url.display = 'http://www.ebay.com/login') :D

oedo
I completely understand that. At the moment I AM show the contents from cart-step-1.php, exactly as if I have submitted a form there. IS there NO way I can still send the viewer TO that page with posted data, exactly as if he posted a form to the page? There is a cURL setopt parameter called CURLOPT_FOLLOWLOCATION which I thought was supposed to follow the location of the url we're curling to, but that seems not to be the case.If I include a header("Location: cart-step-1.php") it fails as the header is already sent.
webfac
yeah that's what i mean by 'you'll need to do it in html' - you actually want to post that data to cart-step-1.php from your browser - so either missing out proc_xxxxxx.php or proc_xxxxxx.php returns an html page which is the form with all parameters filled out and the action set to cart-step-1.php (you can automatically submit a form with javascript if necessary) and then it will give the behaviour you want.
oedo
A: 

After you have done your curl stuff you can redirect the user with header():

header('Location: http://localhost/eterniti/cart-step-1.php');

More complete:

$url = "http://localhost/eterniti/cart-step-1.php";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "error=1&em=$em&fname=$fname&lname=$lname&email1=$email1&email2=$email2&code=$code&area=$area&number=$num&mobile=$mobile&address1=$address1&address2=$address2&address3=$address3&suburb=$suburb&postcode=$postcode&country=$country");
curl_exec($ch);
curl_close($ch);

header('Location: ' . $url);
exit;

Depending on what this site expects on parameters, this might or might not work. If you redirect the browser to this page, it will just be a GET request from the browser. You cannot make the browser sending POST data.


Only thing that comes to my mind (if you want to make the Browser to send the POST data) is:
Instead of using curl, create a form with all values in hidden fields and show a button that says Continue. Then the user has only to press the button.

Felix Kling
To clarify, I want to POST the data to cart-step-1.php AS well as send the user there as well. Do I make sense here? So imagine I replaced cURL with a form submission, I need that same behaviour but I cant post with a form as it is my script processing the data. In essence I want my script to post the data to cart-step-1.php, and this only happens if the data is not validated correctly, ie if the user submitted incorrect data
webfac
@webfac: So you kind of preprocess the data before it is sent to the "real" website right? As I said you could create a new form with all the processed values in hidden fields. Of course this would not be secure in any way, technically advance users can still tamper this data.
Felix Kling
Correct, this processing script returns the data along with error codes if the data was not complete. So yes the script pre-processes the data, and posts it back. I suppose worst case scenario I could append the parameters to the URL and send with a GET method, but it'll look dirty!
webfac