Jump to content

HTML and PHP help please

Go to solution Solved by Guest,

 

I would write to a text file then watch it.

 

On the web side of things.

<!doctype html>
<head>
  <title>Example</title>
</head>

<?php
if (isset($_POST['form_submitted'])) {
    file_put_contents('webInput', $_POST['textInput']."\n", FILE_APPEND);
}
?>

<body>
    <form action="index.php" method="POST"> 
        <div> Text Input: <input type="text" name="textInput"> </div>
        <input type="hidden" name="form_submitted" value="1" />
        <input type="submit" value="Submit">
    </form>
  
</body>
</html>

 

Then in a terminal, do something like this.

watch -n2 tail -5 /path/to/htdocs/webInput

 

In this example we are writing to "webInput" then reading last 5 lines every 2 seconds in a terminal.

 

4 hours ago, SupaKomputa said:

I don't think php can directly talk to the console.

You need some kind of listener that reads the output from the log or database.

So the input you type in has to be stored somewhere and then you run a command in the terminal to read it.

 

You can use exec or passthru, but it opens up a world of security and permission issues, especially when you make it accept outside user input.

These examples probably wont work unless you have setup permissions for it or you have your web server configured incorrectly.

exec("wall ".$_POST['textInput']);

 

passthru("echo ".$_POST['textInput']." >> /dev/pts/1")

Hi, so I want to know how to take an input from 

<input>

and output it on my Raspberry Pi terminal as an 

echo

response. How would I do that?

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1275290-html-and-php-help-please/
Share on other sites

Link to post
Share on other sites

<?php 

echo "<input type="text">";

?>

you probably want to use form tag beforehand.

Ryzen 5700g @ 4.4ghz all cores | Asrock B550M Steel Legend | 3060 | 2x 16gb Micron E 2666 @ 4200mhz cl16 | 500gb WD SN750 | 12 TB HDD | Deepcool Gammax 400 w/ 2 delta 4000rpm push pull | Antec Neo Eco Zen 500w

Link to post
Share on other sites

3 minutes ago, SupaKomputa said:

you probably want to use form tag beforehand.

Ah yes... I'm dumb it's 4:21 am here

 

And how do I link the PHP to HTML?

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

anyway what do you want to do? looks like you dont know what you're doing.

Ryzen 5700g @ 4.4ghz all cores | Asrock B550M Steel Legend | 3060 | 2x 16gb Micron E 2666 @ 4200mhz cl16 | 500gb WD SN750 | 12 TB HDD | Deepcool Gammax 400 w/ 2 delta 4000rpm push pull | Antec Neo Eco Zen 500w

Link to post
Share on other sites

Just now, SupaKomputa said:

anyway what do you want to do? looks like you dont know what you're doing.

I want to basically type something in a webpage and display it on the Raspberry Pi terminal

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

I don't think php can directly talk to the console.

You need some kind of listener that reads the output from the log or database.

So the input you type in has to be stored somewhere and then you run a command in the terminal to read it.

Ryzen 5700g @ 4.4ghz all cores | Asrock B550M Steel Legend | 3060 | 2x 16gb Micron E 2666 @ 4200mhz cl16 | 500gb WD SN750 | 12 TB HDD | Deepcool Gammax 400 w/ 2 delta 4000rpm push pull | Antec Neo Eco Zen 500w

Link to post
Share on other sites

 

I would write to a text file then watch it.

 

On the web side of things.

<!doctype html>
<head>
  <title>Example</title>
</head>

<?php
if (isset($_POST['form_submitted'])) {
    file_put_contents('webInput', $_POST['textInput']."\n", FILE_APPEND);
}
?>

<body>
    <form action="index.php" method="POST"> 
        <div> Text Input: <input type="text" name="textInput"> </div>
        <input type="hidden" name="form_submitted" value="1" />
        <input type="submit" value="Submit">
    </form>
  
</body>
</html>

 

Then in a terminal, do something like this.

watch -n2 tail -5 /path/to/htdocs/webInput

 

In this example we are writing to "webInput" then reading last 5 lines every 2 seconds in a terminal.

 

4 hours ago, SupaKomputa said:

I don't think php can directly talk to the console.

You need some kind of listener that reads the output from the log or database.

So the input you type in has to be stored somewhere and then you run a command in the terminal to read it.

 

You can use exec or passthru, but it opens up a world of security and permission issues, especially when you make it accept outside user input.

These examples probably wont work unless you have setup permissions for it or you have your web server configured incorrectly.

exec("wall ".$_POST['textInput']);

 

passthru("echo ".$_POST['textInput']." >> /dev/pts/1")
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×