Jump to content

Submit form to external site


Mix1988

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273699-submit-form-to-external-site/
Share on other sites

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.