Jump to content

Router Configuration Page


timkoy

Recommended Posts

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

 

 

Link to comment
Share on other sites

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);

}

?>

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.