Solution #1: Prompt for get input inside of anywhere code:

<?php
echo "What do you want to input? ";
$input = rtrim(fgets(STDIN));
echo "I got it:\n" . $input;

Sample output:

# php test.php
What do you want to input? Hello, I'm here!
I got it:
Hello, I'm here!

Solution #2: If you want get input in firstly inline when run php:

<?php
$input = $argv[1];
echo "I got it:\n" . $input;

Sample output:

# php test.php "Hello, I'm here!"
I got it:
Hello, I'm here!

Extra tips:

If you want to integrate CLI and WEB inputs, you can use this magic code:

<?php
if (PHP_SAPI === 'cli') parse_str(implode('&', array_slice($argv, 1)), $_GET);
var_dump($_GET);

And now write for use under CLI:

# php sample.php user=nabikaz website=nabi.ir

And follow the normal routine for the WEB:

http://localhost/sample.php?user=nabikaz&website=nabi.ir

Without defining the number and name of inputs.
Both have the same result. ;-)

array(2) {
  ["user"]=>
  string(7) "nabikaz"
  ["website"]=>
  string(7) "nabi.ir"
}
Answer from Nabi K.A.Z. on Stack Overflow
🌐
Talkerscode
talkerscode.com › howto › how-to-take-input-from-user-in-php-without-form.php
How To Take Input From User In PHP Without Form
In this tutorial we will show you the solution of how to take input from user in PHP without form, here we using readline() method for ask input from user without help of form. The readline() is a built-in function in php that enables us to ...
🌐
Quora
quora.com › How-do-I-get-an-input-value-in-PHP-without-a-form
How to get an input value in PHP without a form - Quora
Answer (1 of 4): If you’re not using a PHP framework … you’re probably looking for the $_REQUEST superglobal. $_REQUEST merges together a $_GET, a $_POST, and $_COOKIE together — it’s a convenience method — not a best practice to ...
🌐
Medium
phpcodertech.medium.com › how-to-get-input-value-from-user-in-php-4b3c5087aa69
How to Get Input Value From User in PHP? | by Bikash Panda | Medium
May 18, 2021 - In this tutorial, we Get Input Value From the User without using any HTML form and the GET and POST method. Here are the steps which we follow to achieve the task, Creating a PHP script with readline() function.
🌐
UCLA Computer Science
web.cs.ucla.edu › classes › fall14 › cs143 › project › php › php_input.html
Handling User Input in PHP
It simply creates an attribute/value binding without need for user action that gets passed transparently along when the form is submitted.
🌐
YouTube
youtube.com › watch
Getting User Input | PHP | Tutorial 10 - YouTube
Source Code - https://www.giraffeacademy.com/web-development/php/This video is one in a series of videos where we'll be looking at programming in PHP. The co...
Published   November 15, 2017
Find elsewhere
Top answer
1 of 3
4

If you don't want to submit a form, the only two other ways of accomplishing this are to click a link with the data as query parameters in the url, or use AJAX to send the data to the server in the background.

update:

Javascript, as usual. You'd put a link or button somewhere on the page with "Send to Server" or whatever for the text. The script would pull your information from the input fields, and then send it on to the server via an AJAX call. Something along these lines (note that I'm using Mootools for all this, as it makes life much easier than having to do the remote calls yourself):

 function clickHandler() {
     var img1 = $$("input[name='img1']")[0].value;

     var r = new Request.JSON({
         'url: 'http://yourserver.example.com/script.php',
         'method': 'post',
         'onComplete': function(success) { alert('AJAX call status: ' + (success ? 'succeeded': 'failed!'); },
         'onFailure': function() { alert('Could not contact server'); },
         'data': 'img1=' + img1
     }).send();
}

and on the server you'd have something like:

<?php

$img1 = mysql_real_escape_string($_POST['img1']);
$idx=1;
$sql="INSERT INTO games SET img1='$img1' WHERE id=$idx";  
$result=mysql_query($sql);

echo (($result !== FALSE) ? 1 : 0);

You'd probably want something more complicated than this, but this is the basis of an AJAX application. Some client-side javascript that makes requests, and a script on the server that handles them and returns any data/errors as needed.

2 of 3
1

Don't know if your completely against using a form or just might not know how to keep it hidden.

You can create a hidden form that submits the info with the click of a button.

<form name="hidden-form" action="youraction.php" method="post">
<input type="hidden" name="submitme" value="I get submitted">
<input type="hidden" name="submitmetoo" value="I get submitted">
<input type="hidden" name="submitmeaswell" value="I get submitted">
<input type="hidden" name="dontleavemeout" value="I get submitted">
<input name="submit" type="submit" value="SUBMIT" />
</form>

However anyone that looks at your html will be able to see this

🌐
Sololearn
sololearn.com › en › Discuss › 985687 › user-input-in-php
User Input in PHP | Sololearn: Learn to code for FREE!
Does anyone know if there's a way to get user input directly from within PHP, such as input() in Python or cin in c++? Thanks in advance! ... You don't. PHP is used to scrape stuff out of HTML. So you create a HTML form.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-read-user-or-console-input-in-php
How to read user or console input in PHP ? - GeeksforGeeks
July 12, 2025 - Method 2: Using fscanf() function works same as the fscanf() function in C. We can read 2 integers from Keyboard(STDIN) as below: ... <?php // Input 1 5 fscanf(STDIN, "%d %d", $a, $b); // Output // The sum of 1 and 5 is 6 echo "The sum of " ...
🌐
DEV Community
dev.to › gbhorwood › writing-command-line-scripts-in-php-part-3-interactive-input-34
writing command line scripts in php: part 3; interactive input - DEV Community
April 8, 2022 - in the previous installment of ... and accepting it one character at a time. stream_get_contents() takes two arguments: the stream (STDIN) and the number of bytes to read (1)....
🌐
PHP
php.net › manual › en › function.readline.php
PHP: readline - Manual
Christian's code works well, but if you want to be able to hide the user input and not echo it to screen, you need to add -s to the read command. The code below is an expanded function that allows an optional prompt and optional hiding of the ...
🌐
Sololearn
sololearn.com › en › Discuss › 3205078 › how-to-input-the-number-in-php
How to input the number in php? | Sololearn: Learn to code for FREE!
as I remember sololearn doesn't have a console for php so php -a for interactive tools won't work but you can try echo '<script>document.write(prompt())</script>'; a little hybrid mixture ... Snehil bro if I want to take input number like this:- $a = readline () Then how can I input like this?
🌐
Medium
medium.com › @olivia.j.01101001 › working-with-forms-in-php-processing-user-input-fc77f7d68a86
Working with Forms in PHP: Processing User Input | by Olivia J | Medium
May 27, 2023 - The $_REQUEST array contains both $_GET and $_POST data, as well as some other variables from cookies or sessions. You can use this array if you do not care about the source of your form data.