I'm trying to redirect the user to touchnet's upay site after they have registered on my site. So this is what my site looks like:
Registration.php
|This is where the user will register for an account along with providing their information
Insert.php
|This is the script that will take all the data posted from `Registration.php`'s form and insert them into the database. But it is also the script that will send the user to the payment page
touchnet
|This is the site that will receive the posted data from `Insert.php` and take care of payment.
So here's my curl settings:
$url='https://secure.touchnet.com:*/Something/*/*.jsp';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
But when the insert finished inserting data and redirects using curl it actually goes to www.domain.com/Something/tapp, www.domain.com being my website. And the browser says /Something not found, obviously because it's not even going to the correct url. Why is cURL failing to redirect to the proper url?
Related
i need to post raw data (XML) to an external site, the XML data is good to go, and is working with the below example...
I am using PHP / cURL
normally i do this by cURL, but in this instance, i need to redirect the client to the URL with the post data...
It works using the below code, but it won't redirect the user to the $URL, this method just prints the data while still being in the script on the same server.
eg:
Post from site1.com to site2.com, the below method keeps the client on site1, but needs to redirect the user to site2.com with the raw post data...
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$val = curl_exec($ch);
curl_close($ch);
i have searched all-over but cannot find a method where it functions as a "regular" form submit where the user is redirected to the URL which the data is posted to... but with RAW post data.
I have access a web service via url and I have created a registration page with form to add users to it. There are a couple of issues though. Firstly, it does not seem to work when wrapped in an if (isset($_POST['submit'])) conditional, which means there are some empty variables (as the user hasn't added their information). This results in warnings above the document for an undefined index and a 400 status and a bad request error due to the curl processing without a form submission.
Secondly, whilst I can fill out the form and successfully add a user to the web service, I cannot work out how to redirect the user after a successful curl posting. I tried putting a header('location: 'somepage.php'); after the curl, wrapper in an if statement checking if the username existed but to no avail. They remain on the registration page looking at the now blank form they just submitted.
$headers= array('Accept: application/json','Content-Type: application/json');
$url = "http://thewebsite.com/user";
$fields = array(
'UserName' => urlencode($_POST['UserName'])
);
$fields_json = json_encode($fields);
// open connection
$ch = curl_init($url);
// set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_json);
// execute post
$result = curl_exec($ch);
// close connection
curl_close($ch);
Hopefully this isn't too broad a question. Any help would be appreciated. Thanks.
I have created a simple classic ASP script that will take a username and password from a post and create session variables. This script works fine if i use a standard html form and redirect to this page. I have a php site and I want to log users into both websites when they log into the php site. To do this i wanted to add a curl request to the login script in php. This would send the password and username over to the script and create the session variables. The response i get from the curl request would suggest that it worked, but it doesnt seem to be saving the session.
Here is the curl request.
$postinfo = "username=".$username."&password=".$password;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
I dont want to paste the full asp script, but this is roughly how it works. The session persists when i login using a html form so i know its working correctly. When the curl request is finished executing it seems that the session variables are populated, but when i visit another page the session does not exist.
'do some stuff with the db to check if the credentials work.
if success = true then
Session("userid") = userid
Session("login") = "good"
Response.Write("Login successful - " & Session("userid"))
else
Response.Write("Login Failed")
end if
When i run the curl request the response is "Login successful - 123". This means not only is the login working, but its also setting the session value. The problem is that when i try to visit the asp site it does not detect any session data.
I have verified that the all links are pointing to https://www.website.com. Both websites are under the same domain name, just 2 different subdirectories/languages. They are both running on the same server.
I am trying to use curl to post data to a form and everything works very well except that when I send the form, it makes use of the server ip address in sending the form but what I really would like to do is to set a custom user agent(The reason why I need to use curl) and I need the client's ip to remain intact.
Here is the code I am using right now.
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
//The next line set the user agent to a custom one.
curl_setopt($ch, CURLOPT_USERAGENT, "Mobile UA :" . $rrand );
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
I want curl to use the client ip address while sending the form and not the address of the server hosting the php script. If it is possible to set custom server address to post the form, that would help as well.
If you were able to forge the request so it looked like it came from the user's network, then the response would also go to the user's network where nothing would be waiting for it.
So no, it is not possible.
Have form data that is to be sent to our email marketing service database (using cURL). Upon receipt of the data, it bounces back a confirmation page.
The problem is the confirmation page displays above the page that has the form on it. How do I get the confirmation page to render on its own? I believe the problem lies in the cURL script I am using, but can't figure it out.
cURL code:
if ($validForm) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://oi.vresp.com?fid=2b68154d4e');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "first_name=$first_name&last_name=$last_name&email_address=$email_address&company_name=$company_name&cust_group=$cust_group");
curl_exec($ch);
curl_close($ch);