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

curl-and-php

HTTP post with PHP & CURL using basic authentication and following redirect

From: Edin Kadribasic <edink_at_proventum.net>
Date: Thu, 22 Mar 2001 19:20:36 +0100

I don't know if this is a bug in CURL or PHP, but I'm having problems
whith a small proxy that is needed for the project I'm working on now.
The problem only occurs if I try to use POST, basic auth and follow the
redirect at the same time. This is PHP proxy code:

if(!empty($password) && !empty($username))
{
  $location="http://194.68.213.78/se$PATH_INFO";
  if ($QUERY_STRING)
    $location.="?".$QUERY_STRING;
 
  $ch = curl_init ();
  curl_setopt($ch,CURLOPT_URL,$location);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_MUTE,1);
  curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
  curl_setopt($ch,CURLOPT_USERAGENT,"Proventum Proxy/1.0 (Linux)");
  curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10s
  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
 
  if ($HTTP_REFERER)
    curl_setopt($ch,CURLOPT_REFERER, $HTTP_REFERER);
 
  if (count ($HTTP_POST_VARS))
    {
      $post=array();
      foreach ($HTTP_POST_VARS as $key => $value)
        $post[]=urlencode($key)."=".urlencode($value);
      $post=implode("&", $post);
      curl_setopt($ch,CURLOPT_POST,1);
      curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
    }
 
  $result = curl_exec ($ch);
  print $result;
  curl_close($ch);
}
else
  print "Proxy error";



I have tried to look at what is happening using strace and gdb with the
following results.


=====================================================
# strace -p 16015
select(8, [7], [], NULL, {1, 0}) = 0 (Timeout)
gettimeofday({985279839, 12555}, NULL) = 0
gettimeofday({985279839, 12743}, NULL) = 0
select(8, [7], [], NULL, {1, 0}) = 0 (Timeout)
gettimeofday({985279840, 12751}, NULL) = 0
gettimeofday({985279840, 12942}, NULL) = 0
select(8, [7], [], NULL, {1, 0}) = 0 (Timeout)
gettimeofday({985279841, 12897}, NULL) = 0
gettimeofday({985279841, 13084}, NULL) = 0

=====================================================
# gdb /data/apache/bin/httpd 16015
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i386-redhat-linux"...

/data/src/cvs-php/ext/curl/.libs/16015: No such file or directory.
Attaching to program: /data/apache/bin/httpd, Pid 16015
Reading symbols from /usr/local/lib/libsybdb.so...done.
Reading symbols from /lib/libm.so.6...done.
Reading symbols from /lib/libcrypt.so.1...done.
Reading symbols from /lib/libdb.so.3...done.
Reading symbols from /lib/libdl.so.2...done.
Reading symbols from /lib/libc.so.6...done.
Reading symbols from /lib/ld-linux.so.2...done.
Reading symbols from /lib/libnss_files.so.2...done.
Reading symbols from /data/apache/libexec/mod_mmap_static.so...done.
Reading symbols from /data/apache/libexec/mod_vhost_alias.so...done.
Reading symbols from /data/apache/libexec/mod_env.so...done.
Reading symbols from /data/apache/libexec/mod_log_config.so...done.
Reading symbols from /data/apache/libexec/mod_log_agent.so...done.
Reading symbols from /data/apache/libexec/mod_log_referer.so...done.
Reading symbols from /data/apache/libexec/mod_mime_magic.so...done.
Reading symbols from /data/apache/libexec/mod_mime.so...done.
Reading symbols from /data/apache/libexec/mod_negotiation.so...done.
Reading symbols from /data/apache/libexec/mod_status.so...done.
Reading symbols from /data/apache/libexec/mod_info.so...done.
Reading symbols from /data/apache/libexec/mod_include.so...done.
Reading symbols from /data/apache/libexec/mod_autoindex.so...done.
Reading symbols from /data/apache/libexec/mod_dir.so...done.
Reading symbols from /data/apache/libexec/mod_cgi.so...done.
Reading symbols from /data/apache/libexec/mod_asis.so...done.
Reading symbols from /data/apache/libexec/mod_imap.so...done.
Reading symbols from /data/apache/libexec/mod_actions.so...done.
Reading symbols from /data/apache/libexec/mod_speling.so...done.
Reading symbols from /data/apache/libexec/mod_userdir.so...done.
Reading symbols from /data/apache/libexec/mod_alias.so...done.
Reading symbols from /data/apache/libexec/mod_rewrite.so...done.
Reading symbols from /data/apache/libexec/mod_access.so...done.
Reading symbols from /data/apache/libexec/mod_auth.so...done.
Reading symbols from /data/apache/libexec/mod_auth_anon.so...done.
Reading symbols from /data/apache/libexec/mod_auth_dbm.so...done.
Reading symbols from /data/apache/libexec/mod_auth_db.so...done.
Reading symbols from /data/apache/libexec/mod_digest.so...done.
Reading symbols from /data/apache/libexec/libproxy.so...done.
Reading symbols from /data/apache/libexec/mod_cern_meta.so...done.
Reading symbols from /data/apache/libexec/mod_expires.so...done.
Reading symbols from /data/apache/libexec/mod_headers.so...done.
Reading symbols from /data/apache/libexec/mod_usertrack.so...done.
Reading symbols from /data/apache/libexec/mod_example.so...done.
Reading symbols from /data/apache/libexec/mod_unique_id.so...done.
Reading symbols from /data/apache/libexec/mod_setenvif.so...done.
Reading symbols from /data/apache/libexec/libphp4.so...done.
Reading symbols from /lib/libpam.so.0...done.
Reading symbols from
/ora01/app/oracle/product/8.0.5/lib/libclntsh.so.1.0...done.
Reading symbols from /lib/libnsl.so.1...done.
Reading symbols from /lib/libresolv.so.2...done.
Reading symbols from /data/php/modules/recode.so...done.
Reading symbols from /usr/lib/librecode.so.0...done.
Reading symbols from /data/php/modules/gd.so...done.
Reading symbols from /usr/lib/libgd.so.1...done.
Reading symbols from /usr/lib/libttf.so.2...done.
Reading symbols from /data/php/modules/gettext.so...done.
Reading symbols from /data/php/modules/imap.so...done.
Reading symbols from /data/php/modules/mysql.so...done.
Reading symbols from /data/php/modules/pcre.so...done.
Reading symbols from /data/php/modules/pgsql.so...done.
Reading symbols from /usr/lib/libpq.so...done.
Reading symbols from /data/php/modules/xml.so...done.
Reading symbols from /data/php/modules/curl.so...done.
---Type <return> to continue, or q <return> to quit---
Reading symbols from /data/php/modules/zlib.so...done.
Reading symbols from /usr/lib/libz.so.1...done.
Reading symbols from /lib/libnss_nisplus.so.2...done.
Reading symbols from /lib/libnss_nis.so.2...done.
Reading symbols from /usr/lib/gconv/ISO8859-1.so...done.
0x4016417e in __select () from /lib/libc.so.6
(gdb) bt
#0 0x4016417e in __select () from /lib/libc.so.6
#1 0xbffe2e80 in ?? ()
#2 0x40940df9 in Curl_perform (curl=0x83153a0) at transfer.c:748
#3 0x4093b0db in curl_easy_perform (curl=0x83153a0) at easy.c:136
#4 0x4093890b in php_if_curl_exec (ht=1, return_value=0x8299bcc,
this_ptr=0x0,
    return_value_used=1) at curl.c:609
#5 0x40285ff8 in execute (op_array=0x8202bc4) at ./zend_execute.c:1494
#6 0x40298e80 in zend_execute_scripts (type=8, file_count=3) at
zend.c:743
#7 0x402aa4c1 in php_execute_script (primary_file=0xbffff7e0) at
main.c:1194
#8 0x402a6ef2 in apache_php_module_main (r=0x80e7d94,
display_source_mode=0)
    at sapi_apache.c:89
#9 0x402a7816 in send_php (r=0x80e7d94, display_source_mode=0,
filename=0x0)
    at mod_php4.c:521
#10 0x402a7848 in send_parsed_php (r=0x80e7d94) at mod_php4.c:532
#11 0x8054453 in ap_invoke_handler ()
#12 0x8067c89 in process_request_internal ()
#13 0x8067cec in ap_process_request ()
#14 0x805f56e in child_main ()
#15 0x805f7ac in make_child ()
#16 0x805f859 in startup_children ()
#17 0x805fe86 in standalone_main ()
#18 0x8060613 in main ()
#19 0x400cf9cb in __libc_start_main (main=0x80602cc <main>, argc=1,
argv=0xbffff9a4,
    init=0x804e994 <_init>, fini=0x809499c <_fini>, rtld_fini=0x4000ae60
<_dl_fini>,
    stack_end=0xbffff99c) at ../sysdeps/generic/libc-start.c:92
(gdb)
=================================

If I disable the redirect it works fine. I was unable to reproduce the
exact problem using command line curl because the post data does not
seem to be submitted to the server and this the redirect respnse never
gets sent back. Then again, I might be missing something. Here's the
command line I tried:

curl -L -u "user:pass" -F
"__Click=0&%25%25ModDate=C125696F00328981&SelectManufacturer=3Com&Select
Category=_15kg5d13cd8g6mobkcljmusj940mi0_"
"http://194.68.213.78/se/info.nsf/frontpage/FrontManufacturers?EditDocum
ent&Seq=1"


Any suggestions?

--
Edin Kadribasic
UNIX Developer
Proventum.NET

_______________________________________________
Curl-and-php mailing list
Curl-and-php_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-and-php
Received on 2001-03-22