Jump to content

Passing form data http


zimmo

Recommended Posts

I have a shopping system set up and all works fine until the page where I ask for the clients invoice details etc... I am using php to validate the form data. This works fine but then after it has validated and you submit the form the data does not get passed as I am using a http location redirect.

 

I have heard people mention curl to pass the data, but have never used this before and dont know where to start. Is there an alternate way of doing this.

 

The form data is passed to another website url of a site that processes our payments.

 

Please can someone tell me the best method?

 

I know I could validate with javascript, but want to stay away from that.

Link to comment
Share on other sites

I have looked at using curl. But ran into problems with that.

 

here is the code I used

 


foreach ( $_POST as $key => $value) {
	$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = 
  curl_init('targeturl.php');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . 
				curl_error($curl_connection);

//close the connection
curl_close($curl_connection);	

 

I am getting the following error:

arning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in

Link to comment
Share on other sites

Sorry so many replies from me, okay, I have now managed to get help of my server guys and no longer getting the error. I think the curl code I have is wrong, as it is not giving an error and most of all NOT posting the data to the other server.

 

I have never used curl before, so some help would be most appreciated, as I need to get this working asap.

 

Here is my curl code:

 

foreach ( $_POST as $key => $value) {
	$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = 
  curl_init('destinationurl.php');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . 
				curl_error($curl_connection);

//close the connection
curl_close($curl_connection);	

 

All I am getting is the following:

 

Array ( => http://destinationurl.php [content_type] => text/html; charset=iso-8859-1 [http_code] => 200 [header_size] => 158 [request_size] => 565 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.270658 [namelookup_time] => 3.3E-5 [connect_time] => 0.128463 [pretransfer_time] => 0.128466 [size_upload] => 350 [size_download] => 4103 [speed_download] => 15159 [speed_upload] => 1293 [download_content_length] => 4103 [upload_content_length] => 0 [starttransfer_time] => 0.270624 [redirect_time] => 0 ) 0-

 

Please anyone any ideas how to sort this out??????

 

Link to comment
Share on other sites

Can anyone please help???

 

I have now managed to get the post data to submit okay, but the problem I have is the data is loading on the same page above my actual website. It is then loading the page at the top with the contents of the data? So I have my website where you submit the form and then when you submit it above that is another web page of the actual page that should be shown on its own on the other server?

 

here is my code now

 


foreach ( $_POST as $key => $value) {
	$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = 
  curl_init('http://www.paymentgatewaysite.com/cf/pay.cfm?userid=123123');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl_connection, CURLOPT_POST, 1);
//perform our request
$result = curl_exec($curl_connection); 
if ($result) {
	echo 'curl post successful <br /><pre>'; print_r($result); echo '</pre>';
}
else {
	echo 'curl post failed <br />';
	echo curl_errno($curl_connection) . '-' . 
	curl_error($curl_connection);
} 

//close the connection
curl_close($curl_connection);	

Link to comment
Share on other sites

This is really getting me down, I have posted on numerous forums and getting nowhere? am I doing this the correct way, as I am getting nowhere.

 

Is curl the right way to do this????? Please there must be someone who has done this type of thing before?

Link to comment
Share on other sites

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.