Forum Moderators: coopster

Message Too Old, No Replies

Accessing data using CURL

CURL and PHP

         

chandar

1:59 pm on Jun 10, 2009 (gmt 0)

10+ Year Member



Hi ,
I am trying to access data using CURL and PHP after authentications,
But i am not able to get the data from the main page instead of that i am getting the data from login page.
Here is the curlinfo printed

<?php
// This is the custom header that needs to be sent to post to your blog.
// Use curl to post to your blog.
$ch = curl_init();
$header[] = "Server: Apache-Coyote/1.1";
$header[] = "Pragma: No-cache"; // browsers keep this blank.
$header[] = "Cache-Control: no-cache";
$header[] = "Expires: Wed, 31 Dec 1969 18:00:00 CST";
$header[] = "Content-Type: text/xml";
$header[] = "Transfer-Encoding: chunked";
curl_setopt($ch, CURLOPT_URL, "http://Ipaddress/login.htm");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);

curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('j_usertzoffset=-0400&j_username=user&j_password=encpass&button=Login'));
curl_setopt ($ch, CURLOPT_COOKIEJAR, "/tmp/cookiejarchandar");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
ob_start();
curl_exec ($ch);
ob_end_clean();
print_r(curl_getinfo($ch));
curl_close($ch);
print "================secondone ====================================================";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejarchandar");
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_URL, "http://ipaddress/report_results.htm?id=report1id");
print "=========================thdddff========================\n";
$data3 = curl_exec($ch);
print_r(curl_getinfo($ch));
print "\n";
curl_close($ch);
echo $data3;
print "=========================thirdone===========================================\n";
print "\n";
?>

===============Output===============================================

[root@nmcsrvnwk0902 chandar]# php test.php
Content-type: text/html
X-Powered-By: PHP/4.3.9

Array
(
[url] => [ipaddress...]
[content_type] => text/html
[http_code] => 200
[header_size] => 201
[request_size] => 84
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.004803
[namelookup_time] => 7.6E-05
[connect_time] => 0.001118
[pretransfer_time] => 0.001153
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.004775
[redirect_time] => 0
)
================secondone ====================================thdddff=====
Array
(
[url] => [ipaddress...]
[content_type] => text/html
[http_code] => 200
[header_size] => 219
[request_size] => 159
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.311563
[namelookup_time] => 2.6E-05
[connect_time] => 0.001108
[pretransfer_time] => 0.001143
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.311548
[redirect_time] => 0
)
[/Code]

[edited by: jatar_k at 6:05 pm (utc) on June 10, 2009]
[edit reason] sidescroll [/edit]

jatar_k

6:04 pm on Jun 10, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld chandar,

it looks like it doesn't like it isn't quite logging in and then bouncing you to a login page

if this is correct

curl_setopt($ch, CURLOPT_POSTFIELDS, array('j_usertzoffset=-0400&j_username=user&j_password=encpass&button=Login'));

then you should look at the script it is targetting

chandar

7:14 am on Jun 11, 2009 (gmt 0)

10+ Year Member



Hi
I have added this form elements based on the values been submited from the actual login page.
I captured this from the packet capture and i am manipulating it.
They have a button with name Login instead of submit button.

Will this code has anything to do with sessions?

Do you want me to post the login page too?

jatar_k

2:27 pm on Jun 11, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you don't actually control the form and you are trying to submit it then it is always difficult to know what they are doing to combat exactly what you are trying to do.

The form processing script obviously doesn't believe your credentials.

is this a form on a site you control?