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

Link to comment
Share on other sites

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

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.