<?php
// create a new CURL resource
$file_path = '/mail';
define("COOKIE_FILE", "c:\cookie.txt");
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://mail.gov.in/iwc/signin");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
session_write_close();
$strCookie = 'PHPSESSID=d095af0e30afc021dd3652734009' . $_COOKIE['PHPSESSID'] . '; path=/mail';
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
curl_setopt ($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS,'fromLogin=true&domainName=nic.in&username=&password=&button=Sign%20In');
$url = curl_getinfo($ch);
// grab URL and pass it to the browser
$data = curl_exec($ch);
echo $data."<pre>";
echo "<pre>";
print_r($url);
// close CURL resource, and free up system resources
curl_close($ch);
?>
whats wrong with my code why i am not able to login directly in their mail
You’re setting a hard-coding a session ID, then loading the COOKIE_FILE. Make sure that there’s not another PHPSESSID cookie in the cookie file already. It may be overriding the session ID you just set manually.
As well, you’re passing in username and password keys in the POST data, but not actually sending the username and password. Maybe you’ve censored them from this post, but it’s worth pointing out. It should most likely be “….&username=SOMEUSER&password=SOMEPASSWORD”.
You then do a
curl_getinfo(), but you have not yet done thecurl_exec()call, so there’s nothing available to get information on, other than some CURL internal settings.You may want to check if
$datais FALSE before outputting it, in case that something failed within CURL: