cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

RE: Navigating website with curl lib

From: fbsd2 <fbsd2_at_a1poweruser.com>
Date: Thu, 12 Jul 2007 15:32:00 -0400

>> When posting fields to a logon page does libcurl automatically click the
>> submit button for you?

>libcurl clicks no buttons at all, libcurl speaks internet-protocols and
they
>don't have buttons.
I can not seem to get the login post step to really work.
The VERBOSE output shows a status code of 200 from the post logon step
but the mysql database holding the valid logon id's show this post of
logon id/pw values did not work because the "last login date/time stamp
in the database was not updated.
The next is the php/curl script followed by the VERBOSE output.
Please review and comment on what could be wrong?

#! /usr/local/bin/php

<?php
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
$ref = "http://www.test.curl.net";
$url1 = 'http://10.0.10.3/mls/mls_fsbo_logon.php';
$url2 = 'http://10.0.10.3/mls/mls_fsbo_menu.php';
$url3 = 'http://10.0.10.3/mls/mls_fsbo_member_update.php';

# Get login page, and save session cookies to pass on.
# Same handle is used all the way through this script.
# Options set in first step are passed forward and cookies are
# dynamically captured and passed between steps until a
# close is encountered.
$ch = curl_init("");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_URL,$url1);
ob_start();
$buffer = curl_exec ($ch);
echo(" Output1: ".$buffer);
ob_end_clean();

# Post login page, with id/pw
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"id=curltest&pw=curltest&action=submit");
ob_start();
$buffer = curl_exec ($ch);
echo(" Output2: ".$buffer);

# get members menu page
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_URL,$url2);
$buffer = curl_exec ($ch);
echo(" Output3: ".$buffer);

# get update members page
curl_setopt($ch, CURLOPT_URL,$url3);
$buffer = curl_exec ($ch);
echo(" Output4: ".$buffer);

# post update members data page
curl_setopt($ch, CURLOPT_URL,$url3);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"zip=99999&action=submit");
$buffer = curl_exec ($ch);
echo(" Output5: ".$buffer);
curl_close ($ch);

@@@@@@@@@@@@@@@@@@@@@@@@@@
Script started on Wed Jul 4 19:00:50 2007
# /root >curl-test.php

* About to connect() to 10.0.10.3 port 80 (#0)
* Trying 10.0.10.3... * connected
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_fsbo_logon.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 200 OK
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Transfer-Encoding: chunked
< Content-Type: text/html

* Connection #0 to host 10.0.10.3 left intact
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> POST /mls/mls_fsbo_logon.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net
Content-Length: 37
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 200 OK
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Transfer-Encoding: chunked
< Content-Type: text/html

* Connection #0 to host 10.0.10.3 left intact
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_fsbo_menu.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=a6823962822ce2ca5d94f364f3898273; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: mls_breakin_attempt.php
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL:
'http://10.0.10.3/mls/mls_breakin_attempt.php'
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_breakin_attempt.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=fa0656a58c6219c834a04f788008d340; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: index.htm
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL: 'http://10.0.10.3/mls/index.htm'
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/index.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 200 OK
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< Last-Modified: Sat, 16 Jun 2007 17:13:14 GMT
< ETag: "5758b1-2dc-46741a2a"
< Accept-Ranges: bytes
< Content-Length: 732
< Content-Type: text/html
* Connection #0 to host 10.0.10.3 left intact
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_fsbo_member_update.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=0eb6f5fc62acedb216028c8afb38f398; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: mls_breakin_attempt.php
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL:
'http://10.0.10.3/mls/mls_breakin_attempt.php'
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_breakin_attempt.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=ae4e3b16b8887066d741465b78876c32; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: index.htm
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL: 'http://10.0.10.3/mls/index.htm'
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/index.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 200 OK
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< Last-Modified: Sat, 16 Jun 2007 17:13:14 GMT
< ETag: "5758b1-2dc-46741a2a"
< Accept-Ranges: bytes
< Content-Length: 732
< Content-Type: text/html
* Connection #0 to host 10.0.10.3 left intact
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> POST /mls/mls_fsbo_member_update.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net
Content-Length: 23
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=1e3fe059bc71e7ae0622fa1f561d3b10; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: mls_breakin_attempt.php
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL:
'http://10.0.10.3/mls/mls_breakin_attempt.php'
* Disables POST, goes with GET
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/mls_breakin_attempt.php HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 302 Found
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< X-Powered-By: PHP/5.2.3
< Set-Cookie: PHPSESSID=a94d712b498763dfe22f35703f21c1b3; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
< Pragma: no-cache
< Location: index.htm
< Transfer-Encoding: chunked
< Content-Type: text/html
* Ignoring the response-body
* Connection #0 to host 10.0.10.3 left intact
* Issue another request to this URL: 'http://10.0.10.3/mls/index.htm'
* Examining connection #0 for reuse
* Re-using existing connection! (#0) with host 10.0.10.3
* Connected to 10.0.10.3 (10.0.10.3) port 80 (#0)
> GET /mls/index.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: 10.0.10.3
Accept: */*
Referer: http://www.test.curl.net

< HTTP/1.1 200 OK
< Date: Wed, 04 Jul 2007 23:00:56 GMT
< Server: Apache/1.3.37 (Unix) PHP/5.2.3
< Last-Modified: Sat, 16 Jun 2007 17:13:14 GMT
< ETag: "5758b1-2dc-46741a2a"
< Accept-Ranges: bytes
< Content-Length: 732
< Content-Type: text/html
* Connection #0 to host 10.0.10.3 left intact
* Closing connection #0
  Output2:

The following is the mls_fsbo_logon.php page
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>learning PHP </title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="00.00-web_style_sheet.css">
</head>
<body>
<body style='font-family: Courier New; font-size: 10pt; line-height: 100%'>
<h1 align=center><b><font size='6'>Sell&nbsp;&nbsp; Kwik</font></b></h1>
<p
align=center>_______________________________________________________________
_______</p>
<align=left>&nbsp;<br><font FACE="Verdana" SIZE="2">

<!-- Form inside of table so it looks nice on page -->
<!-- Notice the php code in the value= tag that is what reshows the data on
bad input data -->
<!-- Notice the TITLE= tag that shows when the user moves the mouse over the
form input field -->

<form method="POST" action="">

<table ALIGN="center" border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="85%">
   <tr><td width="100%"><p align="center"><b><font size="2">FSBO Logon
Information</font></b></td></tr>
</table>

<table ALIGN="center" border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="85%">

  <tr><td width="38%"><font FACE="Verdana" SIZE="2">&nbsp;Logon ID:
</font></td>
      <td width="62%"><input type="text" name="id" size="30" maxlength="15"
          value="" TITLE="Enter 7 to 15 Alpha-Numeric
characters"></font></td></tr>

  <tr><td width="38%"><font FACE="Verdana" SIZE="2">&nbsp;Logon Password:
</td>
      <td width="62%"><input type="password" name="pw" size="30"
maxlength="15"
          value="" TITLE="Enter 6 to 15 Alpha-Numeric
characters"></font></td></tr>

<!-- This is the captcha Security Code Random-Noisy-Image -->
  <tr><td width="38%">&nbsp;<font FACE="Verdana" SIZE="1"><img width=120
height=30 src="button.php" border="1"> Security Code</td>
      <td width="62%"><input MAXLENGTH=5 SIZE=5 name="userdigit" type="text"
value="">
      <font FACE="Verdana" SIZE="1">If you can not read it, submit to get
new one.</font></td></tr
</table>
<table ALIGN="center" border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="85%">
   <tr><td width="100%"><p align="center"><input type="submit"
value="Submit" name="submit"></td></tr>

</table>
</form>
</font>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a target="_self" href="mls_fsbo_forgot_logon.php">Did you
forget your Login ID or Password?</a><br>
<br>

</body></html> Output3: <html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="00.00-web_style_sheet.css">
</head>

<frameset rows="64,*">
  <frame name="banner" scrolling="no" noresize target="contents"
src="00.00_Header.htm">
  <frameset cols="183,*">
    <frame name="contents" target="main" src="mls_products.htm">
    <frame name="main" src="mls_home_page.php">
  </frameset>
  <noframes>
  <body>

  <p>This page uses frames, but your browser doesn't support them.</p>

  </body>
  </noframes>
</frameset>

</html> Output4: <html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="00.00-web_style_sheet.css">
</head>

<frameset rows="64,*">
  <frame name="banner" scrolling="no" noresize target="contents"
src="00.00_Header.htm">
  <frameset cols="183,*">
    <frame name="contents" target="main" src="mls_products.htm">
    <frame name="main" src="mls_home_page.php">
  </frameset>
  <noframes>
  <body>

  <p>This page uses frames, but your browser doesn't support them.</p>

  </body>
  </noframes>
</frameset>

</html> Output5: <html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="00.00-web_style_sheet.css">
</head>

<frameset rows="64,*">
  <frame name="banner" scrolling="no" noresize target="contents"
src="00.00_Header.htm">
  <frameset cols="183,*">
    <frame name="contents" target="main" src="mls_products.htm">
    <frame name="main" src="mls_home_page.php">
  </frameset>
  <noframes>
  <body>

  <p>This page uses frames, but your browser doesn't support them.</p>

  </body>
  </noframes>
</frameset>

</html># /root >exit
exit

Script done on Wed Jul 4 19:01:03 2007

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-07-12