Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of php://input & php://output and when it needs to use? [closed]

Tags:

php

What is the meaning of php://input & php://output and when it needs to use? Please explain with an example.

like image 870
Rahul Avatar asked Aug 25 '11 06:08

Rahul


People also ask

What is input Output in php?

php://output allows you to write to the output buffer mechanism in the same way as print() and echo(). php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.

How to let the user input in php?

To get input from users, you also have to prompt them to enter something. You can use PHP's `readline() function to get this input from the console.

How to input a variable in php?

$a = readline(); In this case, as soon as the user hits enter, the entered value is stored in the variable a. Accept multiple space separated inputs: For this, we use another function explode() together with readline(). The first argument of explode() is the delimiter we want to use.

What is a php stream?

PHP Stream Introduction Streams are the way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior.


1 Answers

These are two of the streams that PHP provides. Streams can be used by functions like fopen, fwrite, stream_get_contents, etc.

php://input is a read-only stream that allows you to read the request body sent to it (like uploaded files or POST variables).

$request_body = stream_get_contents('php://input');

php://output is a writable stream that is sent to the server and will be returned to the browser that requested your page.

$fp = fopen('php://output', 'w');
fwrite($fp, 'Hello World!'); //User will see Hello World!
fclose($fp);

Note that if you are in the CLI, php://output will write data to the command line.

like image 53
Bailey Parker Avatar answered Oct 02 '22 17:10

Bailey Parker