Jump to content

HTML and PHP help please

TheCoder2019
Go to solution Solved by Nayr438,

 

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?

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
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 comment
Share on other sites

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?

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

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 comment
Share on other sites

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

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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

×