read from standard input?

This is a discussion on read from standard input? within the PHP Language forums, part of the PHP Programming Forums category; Hobart Runa Sze schrieb: > I read that passing data via POST means PHP running as CGI needs to > ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-02-2004
Matthias Esken
 
Posts: n/a
Default Re: read from standard input?

Hobart Runa Sze schrieb:

> I read that passing data via POST means PHP running as CGI needs to
> read from standard input buffer instead of global vars. I tried reading
> from $_POST but can't find my data there.
>
> I searched the manual for a function to read from stdin but couldn't
> find any. Does it even exist or do we always use $_POST?


Use $_POST when PHP is running in the context of a webserver. If you use
PHP from the command line there will be no $_POST.

Regards,
Matthias
Reply With Quote
  #2 (permalink)  
Old 06-02-2004
Hobart Runa Sze
 
Posts: n/a
Default read from standard input?

Hello,
I read that passing data via POST means PHP running as CGI needs to
read from standard input buffer instead of global vars. I tried reading
from $_POST but can't find my data there.

I searched the manual for a function to read from stdin but couldn't
find any. Does it even exist or do we always use $_POST?

Any help is appreciated,
Hobart

Reply With Quote
  #3 (permalink)  
Old 06-02-2004
Philipp Kern
 
Posts: n/a
Default Re: read from standard input?

On 2004-06-02, Hobart Runa Sze <hobartsze@h0tmail.com> wrote:
> I searched the manual for a function to read from stdin


You don't want it in this case, but reading from stdin:
$fp = fopen('php://stdin', 'r');
while($line = fgets($fp, 4096) { echo $line; }

HTH,
phil
--
Please send replies (not followups) to the address set in Reply-To.
Philipp Kern - PK2186-RIPE - http://www.philkern.de
Reply With Quote
  #4 (permalink)  
Old 06-03-2004
Hobart Runa Sze
 
Posts: n/a
Default Re: read from standard input?

>
> Use $_POST when PHP is running in the context of a webserver. If you use
> PHP from the command line there will be no $_POST.
>
> Regards,
> Matthias


Thanks for clearing that up, Matthias. However I still this problem...

My script gets run when a form is submitted. If action="write.php",
everything works fine - I can read $_POST["data"].

If action="write.cgi", the script runs and prints out the hardcoded text
but when echoing $_POST["data"] nothing comes out.

What could possibly be the reason?

Hobart

Reply With Quote
  #5 (permalink)  
Old 06-03-2004
Philipp Kern
 
Posts: n/a
Default Re: read from standard input?

On 2004-06-03, Hobart Runa Sze <hobartsze@h0tmail.com> wrote:
> If action="write.cgi", the script runs and prints out the hardcoded text
> but when echoing $_POST["data"] nothing comes out.
> What could possibly be the reason?


PHP is not invoked when the script is named .cgi?

Bye,
phil
--
Please send replies (not followups) to the address set in Reply-To.
Philipp Kern - PK2186-RIPE - http://www.philkern.de
Reply With Quote
  #6 (permalink)  
Old 06-03-2004
FLEB
 
Posts: n/a
Default Re: read from standard input?

Regarding this well-known quote, often attributed to Philipp Kern's famous
"3 Jun 2004 08:58:23 GMT" speech:

> On 2004-06-03, Hobart Runa Sze <hobartsze@h0tmail.com> wrote:
>> If action="write.cgi", the script runs and prints out the hardcoded text
>> but when echoing $_POST["data"] nothing comes out.
>> What could possibly be the reason?

>
> PHP is not invoked when the script is named .cgi?
>
> Bye,
> phil


You can run PHP either as an Apache module (how it usually is), or as a CGI
app.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Reply With Quote
  #7 (permalink)  
Old 06-03-2004
Matthias Esken
 
Posts: n/a
Default Re: read from standard input?

FLEB schrieb:

> Regarding this well-known quote, often attributed to Philipp Kern's famous
> "3 Jun 2004 08:58:23 GMT" speech:
>
>> PHP is not invoked when the script is named .cgi?

>
> You can run PHP either as an Apache module (how it usually is), or as a CGI
> app.


Yes, but my scripts still have the extension ".php", even when I use PHP
as a CGI application.

Regards,
Matthias
Reply With Quote
  #8 (permalink)  
Old 06-03-2004
Hobart Runa Sze
 
Posts: n/a
Default Re: read from standard input?

Matthias Esken wrote:

> FLEB schrieb:
>
>
>>Regarding this well-known quote, often attributed to Philipp Kern's famous
>>"3 Jun 2004 08:58:23 GMT" speech:
>>
>>
>>>PHP is not invoked when the script is named .cgi?

>>
>>You can run PHP either as an Apache module (how it usually is), or as a CGI
>>app.

>
>
> Yes, but my scripts still have the extension ".php", even when I use PHP
> as a CGI application.
>
> Regards,
> Matthias


Yea, my host requires all cgi scripts to be names *.cgi for security
reasons.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0