tags:

views:

69

answers:

4
<?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

A: 

Maybe the referer gets checked, CURLOPT_REFERER.

yene
can u be more clear
A: 

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 the curl_exec() call, so there's nothing available to get information on, other than some CURL internal settings.

You may want to check if $data is FALSE before outputting it, in case that something failed within CURL:

$data = curl_exec($ch);
$info = curl_getinfo($ch);
if ($data === FALSE) {
    print("CURL failed: " . curl_error($ch) . "\n");
}
var_dump($info); // print out full information array from curl
var_dump($data); // print out anything the server may have returned
Marc B
Server ErrorThis server has encountered an internal error which prevents it from fulfilling your request. The most likely cause is a misconfiguration. Please ask the administrator to look for messages in the server's error log. "
array(20) { ["url"]=> string(30) "https://mail.nic.in/mail/mauth" ["content_type"]=> string(9) "text/html" ["http_code"]=> int(500) ["header_size"]=> int(244) ["request_size"]=> int(412) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(20) ["redirect_count"]=> int(0) ["total_time"]=> float(0.031) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0.031) ["size_upload"]=> float(92) ["size_download"]=> float(305) ["speed_download"]=> float(9838) ["speed_upload"]=> float(2967) ["download_content_length"]=>
@user `Please ask the administrator to look for messages in the server's error log`
Pekka
The remote server is returning error code 500 - 'Internal Server Error'. Unless there's something about your POST request that's causing the problem (malformed request breaking their script or something), the error is occuring on the remote server.
Marc B
A: 

Does the site use cookies? What's the error message? Which (obfuscated) commands are you sending?

Erik Cederstrand
Welcome to SO Eric. You can add comments underneath the OP's question if you need something clarified. Answers should be reserved for posts that provide a solution (or part of it).
Pekka
I have provided the coding above plz help me out............
+2  A: 

You seem to be trying to screen scrape a webmail inbox. To get help with that, you need to provide much more info.

However, PHP offers the possibility to access POP3 mailboxes directly: IMAP Functions In the user contributed notes, there is what seems to be a full-fledged code snippet to access POP3 mailboxes.

Pekka
i have provided the coding above plz help me out.............