POST method doesn't work in PHP on the command line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    POST method doesn't work in PHP on the command line


    I am using the php4-cgi Debian package which is based on PHP 4.3.4.

    I have problems when running php4 on the command line. If I say something
    like

    $ php4 index.cgi

    a number of variables are not initialized. For example, $HTTP_GET_VARS is
    not set. To get it set, here's my workaround:

    global $HTTP_GET_VARS;
    parse_str(geten v("QUERY_STRING "),$HTTP_GET_VA RS);

    But, my real problem is that $HTTP_POST_VARS is not set -- I have no easy
    workaround for that. If I set the REQUEST_METHOD environment variable to
    "POST" and CONTENT_LENGTH to some value, the above command ("php4
    index.cgi") does not read the post data from the standard input, as one
    would suppose.

    If I can successfully get the above missing variables to be defined when
    on the command line, I should be able to figure out why php4 CGI scripts
    don't work from thttpd. (Interestingly, php3 scripts work fine.)
    (Ultimately, I would like to get phpwiki to work on thttpd, but I think
    the above problems are unrelated to this combination per-se. Note that
    phpwiki requires that register_global s be set to "on" to work.)

    Just for the record, here's the output from "php4 -i":
    [color=blue]
    > phpinfo()
    > PHP Version => 4.3.4
    >
    > System => Linux darkstar 2.4.19 #10 Wed Sep 11 15:45:42 EDT 2002 i686
    > Build Date => Mar 27 2004 08:01:43
    > Configure Command => '../configure' '--prefix=/usr' '--prefix=/usr' '--with-regex=php' '--enable-force-cgi-redirect' '--with-config-file-path=/etc/php4/cgi' '--disable-rpath' '--enable-memory-limit' '--disable-debug' '--with-layout=GNU' '--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype' '--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro' '--enable-ftp' '--with-gettext' '--enable-mbstring' '--with-pcre-regex=/usr' '--enable-shmop' '--enable-sockets' '--enable-wddx' '--disable-xml' '--with-expat-dir=/usr' '--enable-yp' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr' '--with-openssl=/usr' '--with-exec-dir=/usr/lib/php4/libexec' '--disable-static' '--without-mm' '--without-mysql' '--without-sybase-ct'
    > Server API => Command Line Interface
    > Virtual Directory Support => disabled
    > Configuration File (php.ini) Path => /etc/php4/cgi/php.ini
    > PHP API => 20020918
    > PHP Extension => 20020429
    > Zend Extension => 20021010
    > Debug Build => no
    > Thread Safety => disabled
    > Registered PHP Streams => php, http, ftp, https, ftps, compress.bzip2, compress.zlib
    >
    >
    > This program makes use of the Zend Scripting Language Engine:
    > Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
    >
    >
    > _______________ _______________ _______________ _______________ ___________
    >
    >
    > Configuration
    >
    > PHP Core
    >
    > Directive => Local Value => Master Value
    > allow_call_time _pass_reference => On => On
    > allow_url_fopen => On => On
    > always_populate _raw_post_data => Off => Off
    > arg_separator.i nput => & => &
    > arg_separator.o utput => & => &
    > asp_tags => Off => Off
    > auto_append_fil e => no value => no value
    > auto_prepend_fi le => no value => no value
    > browscap => no value => no value
    > default_charset => no value => no value
    > default_mimetyp e => text/html => text/html
    > define_syslog_v ariables => Off => Off
    > disable_classes => no value => no value
    > disable_functio ns => no value => no value
    > display_errors => On => On
    > display_startup _errors => Off => Off
    > doc_root => no value => no value
    > docref_ext => no value => no value
    > docref_root => no value => no value
    > enable_dl => On => On
    > error_append_st ring => no value => no value
    > error_log => no value => no value
    > error_prepend_s tring => no value => no value
    > error_reporting => 2039 => 2039
    > expose_php => On => On
    > extension_dir => /usr/lib/php4/20020429 => /usr/lib/php4/20020429
    > file_uploads => On => On
    > gpc_order => GPC => GPC
    > highlight.bg => #FFFFFF => #FFFFFF
    > highlight.comme nt => #FF8000 => #FF8000
    > highlight.defau lt => #0000BB => #0000BB
    > highlight.html => #000000 => #000000
    > highlight.keywo rd => #007700 => #007700
    > highlight.strin g => #DD0000 => #DD0000
    > html_errors => On => On
    > ignore_repeated _errors => Off => Off
    > ignore_repeated _source => Off => Off
    > ignore_user_abo rt => Off => Off
    > implicit_flush => Off => Off
    > include_path => .:/usr/share/php:/usr/share/pear => .:/usr/share/php:/usr/share/pear
    > log_errors => Off => Off
    > log_errors_max_ len => 1024 => 1024
    > magic_quotes_gp c => On => On
    > magic_quotes_ru ntime => Off => Off
    > magic_quotes_sy base => Off => Off
    > max_execution_t ime => 30 => 30
    > max_input_time => 60 => 60
    > memory_limit => 8M => 8M
    > open_basedir => no value => no value
    > output_bufferin g => no value => no value
    > output_handler => no value => no value
    > post_max_size => 8M => 8M
    > precision => 12 => 12
    > register_argc_a rgv => On => On
    > register_global s => On => On
    > report_memleaks => On => On
    > safe_mode => Off => Off
    > safe_mode_exec_ dir => no value => no value
    > safe_mode_gid => Off => Off
    > safe_mode_inclu de_dir => no value => no value
    > sendmail_from => me@localhost.co m => me@localhost.co m
    > sendmail_path => /usr/sbin/sendmail -t -i => /usr/sbin/sendmail -t -i
    > serialize_preci sion => 100 => 100
    > short_open_tag => On => On
    > SMTP => localhost => localhost
    > smtp_port => 25 => 25
    > sql.safe_mode => Off => Off
    > track_errors => Off => Off
    > unserialize_cal lback_func => no value => no value
    > upload_max_file size => 2M => 2M
    > upload_tmp_dir => no value => no value
    > user_dir => no value => no value
    > variables_order => EGPCS => EGPCS
    > xmlrpc_error_nu mber => 0 => 0
    > xmlrpc_errors => Off => Off
    > y2k_compliance => On => On
    >
    > bcmath
    >
    > BCMath support => enabled
    >
    > bz2
    >
    > BZip2 Support => Enabled
    > BZip2 Version => 1.0.2, 30-Dec-2001
    >
    > calendar
    >
    > Calendar support => enabled
    >
    > ctype
    >
    > ctype functions => enabled
    >
    > dba
    >
    > DBA support => enabled
    > Supported handlers => cdb cdb_make db4 inifile flatfile
    >
    > exif
    >
    > EXIF Support => enabled
    > EXIF Version => 1.4 $Id: exif.c,v 1.118.2.25 2003/09/22 23:28:07 iliaa Exp $
    > Supported EXIF Version => 0220
    > Supported filetypes => JPEG,TIFF
    >
    > ftp
    >
    > FTP support => enabled
    >
    > gettext
    >
    > GetText Support => enabled
    >
    > iconv
    >
    > iconv support => enabled
    > iconv implementation => glibc
    > iconv library version => 2.3.2
    >
    > Directive => Local Value => Master Value
    > iconv.input_enc oding => ISO-8859-1 => ISO-8859-1
    > iconv.internal_ encoding => ISO-8859-1 => ISO-8859-1
    > iconv.output_en coding => ISO-8859-1 => ISO-8859-1
    >
    > mbstring
    >
    > Multibyte Support => enabled
    > Multibyte (japanese) regex support => enabled
    >
    > mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
    >
    > Directive => Local Value => Master Value
    > mbstring.detect _order => no value => no value
    > mbstring.encodi ng_translation => Off => Off
    > mbstring.func_o verload => 0 => 0
    > mbstring.http_i nput => pass => pass
    > mbstring.http_o utput => pass => pass
    > mbstring.intern al_encoding => ISO-8859-1 => no value
    > mbstring.langua ge => neutral => neutral
    > mbstring.substi tute_character => no value => no value
    >
    > openssl
    >
    > OpenSSL support => enabled
    > OpenSSL Version => OpenSSL 0.9.7d 17 Mar 2004
    >
    > overload
    >
    > User-Space Object Overloading Support => enabled
    >
    > pcre
    >
    > PCRE (Perl Compatible Regular Expressions) Support => enabled
    > PCRE Library Version => 4.5 01-December-2003
    >
    > posix
    >
    > Revision => $Revision: 1.51.2.2 $
    >
    > session
    >
    > Session Support => enabled
    > Registered save handlers => files user
    >
    > Directive => Local Value => Master Value
    > session.auto_st art => Off => Off
    > session.bug_com pat_42 => On => On
    > session.bug_com pat_warn => On => On
    > session.cache_e xpire => 180 => 180
    > session.cache_l imiter => nocache => nocache
    > session.cookie_ domain => no value => no value
    > session.cookie_ lifetime => 0 => 0
    > session.cookie_ path => / => /
    > session.cookie_ secure => Off => Off
    > session.entropy _file => no value => no value
    > session.entropy _length => 0 => 0
    > session.gc_divi sor => 100 => 100
    > session.gc_maxl ifetime => 1440 => 1440
    > session.gc_prob ability => 1 => 1
    > session.name => PHPSESSID => PHPSESSID
    > session.referer _check => no value => no value
    > session.save_ha ndler => files => files
    > session.save_pa th => /tmp => /tmp
    > session.seriali ze_handler => php => php
    > session.use_coo kies => On => On
    > session.use_onl y_cookies => Off => Off
    > session.use_tra ns_sid => Off => Off
    >
    > shmop
    >
    > shmop support => enabled
    >
    > sockets
    >
    > Sockets Support => enabled
    >
    > standard
    >
    > Regex Library => Bundled library enabled
    > Dynamic Library Support => enabled
    > Path to sendmail => /usr/sbin/sendmail -t -i
    >
    > Directive => Local Value => Master Value
    > assert.active => 1 => 1
    > assert.bail => 0 => 0
    > assert.callback => no value => no value
    > assert.quiet_ev al => 0 => 0
    > assert.warning => 1 => 1
    > auto_detect_lin e_endings => 0 => 0
    > default_socket_ timeout => 60 => 60
    > safe_mode_allow ed_env_vars => PHP_ => PHP_
    > safe_mode_prote cted_env_vars => LD_LIBRARY_PATH => LD_LIBRARY_PATH
    > url_rewriter.ta gs => a=href,area=hre f,frame=src,inp ut=src,form=,fi eldset= => a=href,area=hre f,frame=src,inp ut=src,form=,fi eldset=
    > user_agent => no value => no value
    >
    > tokenizer
    >
    > Tokenizer Support => enabled
    >
    > wddx
    >
    > WDDX Support => enabled
    > WDDX Session Serializer => enabled
    >
    > xml
    >
    > XML Support => active
    > XML Namespace Support => active
    > EXPAT Version => expat_1.95.6
    >
    > yp
    >
    > YP Support => enabled
    >
    > zlib
    >
    > ZLib Support => enabled
    > Compiled Version => 1.2.1
    > Linked Version => 1.2.1
    >
    > Directive => Local Value => Master Value
    > zlib.output_com pression => Off => Off
    > zlib.output_com pression_level => -1 => -1
    > zlib.output_han dler => no value => no value
    >
    > Additional Modules
    >
    > Module Name
    > filepro
    > sysvsem
    > sysvshm
    >
    > Environment
    >
    > Variable => Value
    > USER => robert
    > LOGNAME => robert
    > HOME => /home/robert
    > PATH => .:/home/robert/bin:/home/robert/bin/linux:/usr/local/lang:/bin:/usr/bin:/usr/ucb:/usr/old:/usr/etc:/etc:/sbin:/usr/sbin:/usr/5bin
    > SHELL => /usr/bin/tcsh
    > PLATFORM => linux
    > TRASHDIR => /home/robert/trash
    > LD_LIBRARY_PATH => /home/robert/lib/local/darkstar:/home/robert/lib:/home/robert/lib/local:/home/robert/lib/gnu:/home/robert/lib/public
    > REMOTEHOST =>
    > TERMINFO => /home/robert/.terminfo
    > MANPATH => /home/robert/man:/usr/man:/usr/share/man:/home/robert/man/X11:/home/robert/man/cat1:/home/robert/man/index.bt:/home/robert/man/index.db.gz:/home/robert/man/local:/home/robert/man/man1:/home/robert/man/perl:/home/robert/man/whatis
    > SHLVL => 2
    > HOSTTYPE => i386-linux
    > VENDOR => intel
    > OSTYPE => linux
    > MACHTYPE => i386
    > PWD => /home/robert
    > GROUP => robert
    > HOST => darkstar
    >
    > PHP Variables
    >
    > Variable => Value
    > PHP_SELF =>
    > _SERVER["USER"] => robert
    > _SERVER["LOGNAME"] => robert
    > _SERVER["HOME"] => /home/robert
    > _SERVER["PATH"] => .:/home/robert/bin:/home/robert/bin/linux:/usr/local/lang:/bin:/usr/bin:/usr/ucb:/usr/old:/usr/etc:/etc:/sbin:/usr/sbin:/usr/5bin
    > _SERVER["SHELL"] => /usr/bin/tcsh
    > _SERVER["PLATFORM"] => linux
    > _SERVER["TRASHDIR"] => /home/robert/trash
    > _SERVER["LD_LIBRARY_PAT H"] => /home/robert/lib/local/darkstar:/home/robert/lib:/home/robert/lib/local:/home/robert/lib/gnu:/home/robert/lib/public
    > _SERVER["REMOTEHOST "] =>
    > _SERVER["TERMINFO"] => /home/robert/.terminfo
    > _SERVER["MANPATH"] => /home/robert/man:/usr/man:/usr/share/man:/home/robert/man/X11:/home/robert/man/cat1:/home/robert/man/index.bt:/home/robert/man/index.db.gz:/home/robert/man/local:/home/robert/man/man1:/home/robert/man/perl:/home/robert/man/whatis
    > _SERVER["SHLVL"] => 2
    > _SERVER["HOSTTYPE"] => i386-linux
    > _SERVER["VENDOR"] => intel
    > _SERVER["OSTYPE"] => linux
    > _SERVER["MACHTYPE"] => i386
    > _SERVER["PWD"] => /home/robert
    > _SERVER["GROUP"] => robert
    > _SERVER["HOST"] => darkstar
    > _SERVER["PHP_SELF"] =>
    > _SERVER["SCRIPT_NAM E"] =>
    > _SERVER["SCRIPT_FILENAM E"] =>
    > _SERVER["PATH_TRANSLATE D"] =>
    > _SERVER["DOCUMENT_R OOT"] =>
    > _SERVER["argv"] => Array
    > (
    > )
    >
    > _SERVER["argc"] => 0
    > _ENV["USER"] => robert
    > _ENV["LOGNAME"] => robert
    > _ENV["HOME"] => /home/robert
    > _ENV["PATH"] => /usr/barra/frame3.1/bin:.:/home/robert/bin:/home/robert/bin/linux:/usr/local/lang:/usr/atria/bin:/disks/lazarus/home/sybase:/usr/lang:/bin:/usr/bin:/usr/ucb:/usr/old:/usr/etc:/etc:/sbin:/usr/sbin:/net/t_rex/disk2/arms/import/gnu/bin:/usr/5bin
    > _ENV["SHELL"] => /usr/bin/tcsh
    > _ENV["PLATFORM"] => linux
    > _ENV["TRASHDIR"] => /home/robert/trash
    > _ENV["LD_LIBRARY_PAT H"] => /home/robert/lib/local/darkstar:/home/robert/lib:/home/robert/lib/local:/home/robert/lib/gnu:/home/robert/lib/public
    > _ENV["REMOTEHOST "] =>
    > _ENV["TERMINFO"] => /home/robert/.terminfo
    > _ENV["MANPATH"] => /home/robert/man:/usr/man:/usr/share/man:/home/robert/man/X11:/home/robert/man/cat1:/home/robert/man/index.bt:/home/robert/man/index.db.gz:/home/robert/man/local:/home/robert/man/man1:/home/robert/man/perl:/home/robert/man/whatis
    > _ENV["SHLVL"] => 2
    > _ENV["HOSTTYPE"] => i386-linux
    > _ENV["VENDOR"] => intel
    > _ENV["OSTYPE"] => linux
    > _ENV["MACHTYPE"] => i386
    > _ENV["PWD"] => /home/robert
    > _ENV["GROUP"] => robert
    > _ENV["HOST"] => darkstar
    >
    > PHP License
    > This program is free software; you can redistribute it and/or modify
    > it under the terms of the PHP License as published by the PHP Group
    > and included in the distribution in the file: LICENSE
    >
    > This program is distributed in the hope that it will be useful,
    > but WITHOUT ANY WARRANTY; without even the implied warranty of
    > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    >
    > If you did not receive a copy of the PHP license, or have any
    > questions about PHP licensing, please contact license@php.net.[/color]

  • Phil Roberts

    #2
    Re: POST method doesn't work in PHP on the command line

    With total disregard for any kind of safety measures
    pzf6dun02@sneak email.com (Robert) leapt forth and uttered:
    [color=blue]
    >
    > I am using the php4-cgi Debian package which is based on PHP
    > 4.3.4.
    >
    > I have problems when running php4 on the command line. If I say
    > something like
    >
    > $ php4 index.cgi
    >
    > a number of variables are not initialized. For example,
    > $HTTP_GET_VARS is not set. To get it set, here's my workaround:
    >[/color]

    To read command line arguments use $_SERVER['argc'] (to get the
    argument count) and $_SERVER['argv'] (to get an array of passed
    arguments)

    --
    Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/

    Comment

    • Robert

      #3
      Re: POST method doesn't work in PHP on the command line

      Parsing arguments is indeed useful, but I'm curious as to why

      $ php4 index.cgi

      with REQUEST_METHOD (=POST) and CONTENT_LENGTH environment variables does
      not read the body of the CGI request. Perhaps if I can get to that point,
      I can figure out why $HTTP_POST_VARS (or $GLOBALS['HTTP_POST_VARS ']) is
      not getting set.

      Thanks.
      [color=blue]
      > From: Phil Roberts <philrob@HOLYfl atnetSHIT.net>
      > Date: Mon, 05 Apr 2004 02:28:37 -0500
      >
      > With total disregard for any kind of safety measures
      > pzf6dun02@sneak email.com (Robert) leapt forth and uttered:
      >[color=green]
      > > I am using the php4-cgi Debian package which is based on PHP
      > > 4.3.4.
      > >
      > > I have problems when running php4 on the command line. If I say
      > > something like
      > >
      > > $ php4 index.cgi
      > >
      > > a number of variables are not initialized. For example,
      > > $HTTP_GET_VARS is not set. To get it set, here's my workaround:
      > >[/color]
      >
      > To read command line arguments use $_SERVER['argc'] (to get the
      > argument count) and $_SERVER['argv'] (to get an array of passed
      > arguments)
      >
      > --
      > Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/[/color]

      Comment

      Working...