zimmo Posted October 5, 2010 Share Posted October 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/ Share on other sites More sharing options...
zimmo Posted October 5, 2010 Author Share Posted October 5, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119369 Share on other sites More sharing options...
zimmo Posted October 5, 2010 Author Share Posted October 5, 2010 If anyone can help me with a workaround be most grateful Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119400 Share on other sites More sharing options...
zimmo Posted October 6, 2010 Author Share Posted October 6, 2010 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119507 Share on other sites More sharing options...
zimmo Posted October 6, 2010 Author Share Posted October 6, 2010 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?????? Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119532 Share on other sites More sharing options...
trq Posted October 6, 2010 Share Posted October 6, 2010 The general process is to validate and process within the same script. Do you need to pass this data to a third party or something? Why are you doing it in two steps? Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119541 Share on other sites More sharing options...
zimmo Posted October 6, 2010 Author Share Posted October 6, 2010 My script validates the data and then I assumed that once done and checked it would send the data to the third party which is where it needs to go? I have not used or done this before. Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119542 Share on other sites More sharing options...
zimmo Posted October 6, 2010 Author Share Posted October 6, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119557 Share on other sites More sharing options...
zimmo Posted October 6, 2010 Author Share Posted October 6, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/215225-passing-form-data-http/#findComment-1119624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.