I have written a PHP script which allows me to modify and update a file on a webpage, which works, but the script right now presents the entire contents of the file in a text area. I would like to extract just the string from the file and pre-populate it in a form text field (instead of a text area).
Below are the two files I need to update. I would like to just update the IP addresses. So the form would ideally show that mail.helloworld.com current maps to "208.164.222.2" and populate that IP address in a form text field. Same idea for the /etc/postfix/main.cf file as shown below.
/etc/hosts
IPAddress Hostname Alias 127.0.0.1 localhost deep.openna.com 208.164.222.2 mail.helloworld.com mail 208.164.222.3 web.helloworld.com web
/etc/postfix/main.cf
relayhost= 192.168.1.10
===
Current working script using textarea:
<form action="<?php echo $PHP_SELF;?>" method="post">
<textarea rows="13" cols="110" name="content">
<?
$fn = "/etc/postfix/main.cf";
print htmlspecialchars(implode("",file($fn)));
?>
</textarea></br>
<input id= "relayhost_button" type="submit" value="Update">
</form>
<?
$fn = "/etc/postfix/main.cf";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=done.php\" />
";
?>
Here is the current textarea based form:
New text field based form I want:
As always, thanks folks!