/    Sign up×
Community /Pin to ProfileBookmark

Need help on PHP Curl

Hi Team,

I am trying to fetch the data from a particular web page using Php curl but unable to do it.Below is my code.It would be great if anyone can help me out in this.

<?php
error_reporting(E_ALL ^ E_NOTICE);

$urlLogin = ‘https://vrl.lta.gov.sg/lta/vrl/action/enquireTransferFeeProxy?FUNCTION_ID=F0501015ET‘;
$urlSecuredPage = ‘https://vrl.lta.gov.sg/lta/vrl/action/enquireTransferFeeProxy?FUNCTION_ID=F0501015ET‘;

// POST names and values to support login
$namevehicleNo=’vehicleNo’; // the name of the vehicle number textbox on the login form
$nametransferDate=’transferDate’; // the name of the date textbox on the login form
$namebutton=’button’; // the name of the login button (submit) on the login form
$valvehicleNo =’GZ2466G’; // the value to vehicle number
$valtransferDate =’08052013′; // this date should be current date
$valbutton =’I Agree’; // the text value of the login button itself

$cookies = ‘tmpcookie.txt’;

$ch = curl_init();

$postData = $namevehicleNo.’=’.$valvehicleNo
.’&’.$nametransferDate.’=’.$valtransferDate
.’&’.$namebutton.’=’.$valbutton
;

curl_setOpt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_URL, $urlLogin);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$data = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $urlSecuredPage);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data1=curl_exec($ch);

echo $data;

if(curl_errno($ch)) {
echo curl_error($ch);
}
else{
$file = ‘content_mjob1.html’;

$fh = fopen($file, ‘w’);// Open a file for writing.
if(!$fh){

echo “Unable to create $file”; // Couldn’t create the file.
}
else {
fwrite($fh, $data.”<br><br>Data1″.$data1); // Write the retrieved //html to the file.
echo “Saved $file”;
fclose($fh);
}
}

/************************************************
*
that’s it! Close the curl handle
**
**********************************************/
curl_close($ch);

?>

Kindly suggest.

Thanks in advance!!!

Regards,
Deepak

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@rossytzoltanMay 09.2013 — I haven't tested your code but at first glance it appears you are missing the certificate check options, since you're querying a https protocol.

Try adding the following options:

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
×

Success!

Help @deepak12286 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...