timkoy Posted November 18, 2010 Share Posted November 18, 2010 Hi Guys, I'm a bit new to php coding, so dont really know what the best way to code this up. I want to make a router configuration page, such as it shows the link status (ip/gatewatway etc) and also have input selections such as to turn on/off wifi / dhcp etc. Ideally I would like the data stored and written to a text file as the php server is running on a linux arm embedded system. At present I have been able to read back from a text file the corresponding values for each of the status information (these are stored on a seperate line), but I'm having difficulty writing and reading the input selection boxes, such as when the dhcp is disabled I need it to write to a file that its been disabled and refresh the page to allow entry of the static ip box and then when the apply button is pressed the value is written to the file. This may be out of my depth, hopefully someone could give me some pointers. I feel that the text file might not be the best way of storing and recalling values but I don't know of another way. Many Thanks Tim Quote Link to comment https://forums.phpfreaks.com/topic/219068-router-configuration-page/ Share on other sites More sharing options...
trq Posted November 18, 2010 Share Posted November 18, 2010 fopen, fread, fwrite. Where exactly are you stuck? Code would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/219068-router-configuration-page/#findComment-1136020 Share on other sites More sharing options...
timkoy Posted November 18, 2010 Author Share Posted November 18, 2010 Hi, Thanks for you quick reply. Im looking at writing a checkbox value into a file. When the submit button is clicked I write the value to the file on a specific line. Then I want to read the file after its been submitted and the value is read back onto that page. I'm finding when I submit that value the value changed in the text file (from checked to unchecked or vice versa) but the page after submittion doesn't change. Only when the page is manually refreshed does the value change. I use the following to check the value of the text file: <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <input type="checkbox" name="ch1" value="DHCPY" <?php echo $lines[6]; ?> /> Yes And use this to write the value to the file: if (isset($_POST['Submit1'])) if ($_POST['ch1'] == 'DHCPY') {$ch1 = $_POST['ch1']; if ($ch1 == 'DHCPY') {$char1 = 'checked';} else {$char1 = 'unchecked';} } if (isset($_POST['Submit1'])) { $data = "ip.txt"; $file = file($data); $i = 6; $yourArray = array($char1); $row = explode(",",$file[$i]); for ($j=0;$j<count($row);$j++) { $row[$j] = $yourArray[$j]; } $fp = fopen('ip.txt', 'r'); fseek($fp, 0); $file[$i] =implode(",",$row); $content = implode("",$file); $open = fopen($data,"w"); fwrite($open,$content); fclose($fp); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219068-router-configuration-page/#findComment-1136025 Share on other sites More sharing options...
timkoy Posted November 22, 2010 Author Share Posted November 22, 2010 The problem I am having is when I click the checkbox and submit the form, The text file does change to the correct value but the page displayed afterwards does not reflected the changed file. Then when I go to refresh the page the value of the checked corrects itself to the vlaue in the file. I've tried adding javscript 'onsubmit=reload' thou this doesn't help matters. Help really would be welcome. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219068-router-configuration-page/#findComment-1137953 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.