Need help on PHP Curl

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: Need help on PHP Curl

Post by sandeep605085 » Wed May 08, 2013 10:50 am

Hi,

when your code is executed then the content_mjob1.html is created in the same directory where the contents are from the variable $data1.

i guess including below code same as for second url that you did in curl is writing the data from $data variable too in that file.


curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

to the end of below for $data.
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);


Thanks,
Sandeep Agrawal
Mindfire Solutions.

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: Need help on PHP Curl

Post by sandeep605085 » Thu May 09, 2013 11:13 am

Yes, i did run the code.
Below is the modified code i ran which access only urlSecuredPage page and it created the file content_mjob1.html in the same directory which has the site content.
Thought there are some issues in displaying the images but text contents are there.

<?php
$urlSecuredPage = 'https://vrl.lta.gov.sg/lta/vrl/action/e ... 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 = 'tmp\cookie.txt';

$ch = curl_init();

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

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);

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);
}
}
curl_close($ch);
?>


Thanks,
Sandeep Agrawal
Mindfire Solutions.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest