Note that there are some explanatory texts on larger screens.

plurals
  1. POphp form exec, sed and file_get_contents
    text
    copied!<p>I am working on a script to edit a file on my vps, so far thanks to the help from a user here I have the following:</p> <pre><code> &lt;?php if(!empty($_REQUEST['color_choice'])){ exec('sed -i '.escapeshellarg('s/color=.*/color='.$_REQUEST['color_choice'].'/g')." /home/user/colors/color.choices"); echo 'File color choice has been updated'; } ?&gt; &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt; &lt;select name="color_choice"&gt;; &lt;option value="red"&gt;red&lt;/option&gt;; &lt;option value="blue"&gt;blue&lt;/option&gt;; &lt;option value="black"&gt;black&lt;/option&gt;; &lt;option value="orange"&gt;orange&lt;/option&gt;; &lt;/select&gt; &lt;input type="submit" name="Submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>This changes the values as needed but I have one issue I am still trying to solve. The script does not get the current value that is in the file itself, so when I first visit the page it always says "red". After I make a change it still says "red" on the php form.</p> <p>Edit: I would like the form to always display the current value in the color.choices file, instead of just going back to "red" every time. If I change the value on the form to "blue" I want the form to display that the current value in the file is set to "blue".</p> <p>I have been told I need to use "file_get_contents" to first retrieve the value from the file itself. I have made a few attempts but I am getting no where. If I need to add more information please let me know!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload