The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Post to external site with curl
Discuss Post to external site with curl in the PHP Development forum on Dev Shed. Post to external site with curl PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 28th, 2013, 04:12 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
|
Post to external site with curl
Hi, i am trying to post something to external site, and i found out best way to do this is cURL.
Here is my code:
PHP Code:
<html>
<body>
<?php
include('simple_html_dom.php');
$url = "example.com";
$a = "744bhz";
$html = new simple_html_dom();
$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_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'pregnr=' . urlencode($a));
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?>
</body>
</html>
Problem is it only loads me blank page nothing else, i have error reporting enabled in php.ini, but no errors, just blank page.
Site html is like this:
Code:
<FORM NAME="kindlustuskate" METHOD="POST" ACTION="SYSADM.LK_INFOKESKUS_PKT.kindlustuskate">
<input type="hidden" name="plang" value="ENG">
<TABLE width=100% CELLPADDING=3 CELLSPACING=0 BORDER=0>
<tr>
<td align="right" width=350>Registration plate number</td>
<td width=10> </td>
<td><input type="text" name="pregnr" value=""> <font size="1">For example 000XXX</font></td>
</tr>
<tr>
<td align="right" width=350>Vehicle VIN code</td>
<td width=10> </td>
<td><input type=text name=pvin value=> <font size=1>For example 45XXXXXXXXXXXXXXXXX65</font></td>
</tr>
<tr>
<td align="right" width=350>Insurance policy number</td>
<td width=10> </td>
<td><input type=text name=ppolnr value=""> <font size=1>For Example E0000000T</font></td>
</tr>
<tr>
<td align="right" width=350>Date of validity</td>
<td width=10> </td>
<td><input type=text name=pkuup value=""> <font size=1>dd.mm.yyyy</font></td>
</tr>
<tr>
<td align=right valign=top>Area of validity</td>
<td align=right valign=top> </td>
<td align=left valign=middle>
<input type=radio name="pala" checked value="1">European Economic Area (EEA) member state or Switzerland<br>
<input type="radio" name="pala" value="2">Green card system country<br>
</td></tr>
<tr>
<td align="right" width=350> </td>
<td width=10> </td>
<td><input type="submit" name="potsi" value="Find"></td>
</tr>
</table>
</form>
Site is https, i dont know if this matters or not, but ihave set sssl verify false in curl anyway.
I have messed with this for many hours, any ideas?
|

January 28th, 2013, 05:32 PM
|
|
|
Why do people just automatically assume every call they makes succeeds without checking?
php Code:
Original
- php Code |
|
|
|
$result = curl_exec($ch); if ($result === FALSE) { echo ("ERROR: " . curl_error ($ch)); } curl_close($ch);
If the error you're getting is
Code:
ERROR: error:14077417:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert illegal parameter
then add
php Code:
Original
- php Code |
|
|
|
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
__________________
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!
Last edited by ptr2void : January 28th, 2013 at 05:35 PM.
|

January 28th, 2013, 07:18 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
And you'll have to pass more than just the license plate number otherwise the form just redisplays itself.
|

January 29th, 2013, 02:36 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by requinix And you'll have to pass more than just the license plate number otherwise the form just redisplays itself. |
But in original site i can just input license plate and click submit, why cant i do this with curl?
vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate
Just add https in front of it, i cant post live links here.
For example 217thd.
|

January 29th, 2013, 03:19 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Because not entering values is not the same as not passing them along at all.
|

January 29th, 2013, 03:26 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Time spent in forums: 4 m 28 sec
Reputation Power: 0
|
|
|
this matters or not
i dont know if this matters or not, but ihave set sssl verify false in curl anyway.
|

January 29th, 2013, 05:14 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by requinix Because not entering values is not the same as not passing them along at all. |
But how can i pass empty value with curl, i tried "0" but that wont work. It fills form with 0.
Maybe
PHP Code:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'formname=');
??
|

January 29th, 2013, 11:48 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
I tried with
Code:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'formname=');
Nothing, it just loads the site as anything is not submited, anyone have any ideas?
PHP Code:
<html>
<body>
<?php
include('simple_html_dom.php');
$url = "https://vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate?plang=EST";
$a = "744bhz";
$html = new simple_html_dom();
$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_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'pregnr=' . urlencode($a));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'pvin=');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'ppolnr=');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'pkuup=');
$result = curl_exec($ch);
if ($result === FALSE)
{
echo ("ERROR: " . curl_error($ch));
}
curl_close($ch);
echo $result;
?>
</body>
</html>
|

January 29th, 2013, 12:10 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
All those curl_setopt()s you have are overwriting each other.
Give it an array of the values you want to send.
|

January 29th, 2013, 01:03 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by requinix All those curl_setopt()s you have are overwriting each other
Give it an array of the values you want to send. |
Thanks for the hint, i made an array with values, but i am still not sure if passing empty data is done right, anyway still no success, script still loads site as no data has been entered.
Code with changes:
PHP Code:
<html>
<body>
<?php
include('simple_html_dom.php');
$url = "https://vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate?plang=EST";
$data = array('pregnr' => '217thd', 'pvin' => '', 'ppolnr' => '', 'pkuup' => '' );
$html = new simple_html_dom();
$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_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if ($result === FALSE)
{
echo ("ERROR: " . curl_error($ch));
}
curl_close($ch);
echo $result;
?>
</body>
</html>
I appreaciate any help , since i am newbie in php 
|

January 29th, 2013, 02:22 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
That's right, but you still haven't included all the form fields.
Example: when you click a named submit button, its name and value are included in the request.
|

January 29th, 2013, 02:38 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 10
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
|
|
[QUOTE=requinix]That's right, but you still haven't included all the form fields.
Example: when you click a named submit button, its name and value are included in the request.[/QUOTE
Ha, i see, thank you very much !!!
Got it working
PHP Code:
$data = array('plang' => 'EST','pregnr' => '217thd', 'pvin' => '', 'ppolnr' => '', 'pkuup' => '', 'pala' => '1', 'potsi' => 'Otsi' );
|

February 6th, 2013, 07:28 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 3 m 38 sec
Reputation Power: 0
|
|
Thank You mate sincerely so much for this topic!
Was just working with the same god damn insurance data reading issue and struggling with similar error, but You made my life so much easier
Tauno
Quote: | Originally Posted by MikkM [QUOTE=requinix]That's right, but you still haven't included all the form fields.
Example: when you click a named submit button, its name and value are included in the request.[/QUOTE
Ha, i see, thank you very much !!!
Got it working
PHP Code:
$data = array('plang' => 'EST','pregnr' => '217thd', 'pvin' => '', 'ppolnr' => '', 'pkuup' => '', 'pala' => '1', 'potsi' => 'Otsi' );
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|