Mix1988 Posted January 27, 2013 Share Posted January 27, 2013 Hello, i am pretty new to php, and need a little help. I want to submit a value to external site. This external site has a form called "form1" and button called "button1" , form method is post. I have googled for hours and now know that i must use cURL, this is what i have managed to do so far: <HTML> <?php $url = "http://example.com/page2"; $a = "blabla"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FAILonerror, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'form1=' . urlencode($a)); $result = curl_exec($ch); curl_close($ch); echo $result; ?> </HTML> This code gives me no erros, nothing at all only loads blank page, any advice what i am doing wrong? Best Regards Mix Quote Link to comment https://forums.phpfreaks.com/topic/273699-submit-form-to-external-site/ Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 Since you get only a blank page with no errors or output, you need to enable error reporting, and set it to E_ALL. I don't see any errors, but this isn't your actual code, so it's hard to tell what the problem might be without an error. Quote Link to comment https://forums.phpfreaks.com/topic/273699-submit-form-to-external-site/#findComment-1408563 Share on other sites More sharing options...
Mix1988 Posted January 27, 2013 Author Share Posted January 27, 2013 Ok i finally got it so far, that it loads me the page, but it loads it as no post function is made. Code is as follows, unchanged. <?php $url = "http://195.80.106.137:9050/soidukiPiirang"; $a = "217thd"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FAILonerror, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'form1=' . urlencode($a)); $result = curl_exec($ch); curl_close($ch); echo $result; ?> I am not sure if curl does not post data from variable $a to form1, or target site makes it hard to get info from there somehow... If i insert value by browser, then site loads info fine. Mix Quote Link to comment https://forums.phpfreaks.com/topic/273699-submit-form-to-external-site/#findComment-1408582 Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 Are you sure you don't need to use GET and not POST? If you can do it in your URL address bar, that's the GET method, not POST. Quote Link to comment https://forums.phpfreaks.com/topic/273699-submit-form-to-external-site/#findComment-1408583 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.