• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

need help to understand php code

Status
Not open for further replies.

Parth86

Member
Hello
I don't have knowledge about php coding. I am trying to understand the part of php program. its related to ip address. can anyone tell me whats happening in program. what's the use of this part?
C:
<?php
error_reporting(0);
if ($_POST) {

$file_path = "//192.158.0.100/PRASHANT/Device control/device_log.txt";
    $myfile = fopen($file_path, "w") or die("Unable to open file!");
    $txt = $_POST['device']." ".$_POST['switch']."\n";
    fwrite($myfile, $txt);
    fclose($myfile);
}

?>
 

Parth86

Member
This just appends the file "device_log.txt" with an error. It writes which device and then the error then a new line..
does this code work in following manner
suppose there are two system ,server system and client system
1. client system try to obtained the ip address of server system and try to set connection
2. client system continuously check connection is successful or not if the connection is not successful then it will again try to obtain IP address of server system
3. If the connection is successful with the server system then the two system's are ready for the communication
 

Parth86

Member
I don't think so..

This is a web posing thing on receiving an error... This only opens a file and updates the a log.. so someone can debug at a later date..
I don't have knowledge about PHP programming that's why I posted small part of program to find out whats happening in program. I am trying to understand what the purpose of this program?
C:
<?php
error_reporting(0);
if ($_POST) {

$file_path = "//192.158.0.100/PRASHAN/Device control/device_log.txt";
    $myfile = fopen($file_path, "w") or die("Unable to open file!");
    $txt = $_POST['device']." ".$_POST['switch']."\n";
    fwrite($myfile, $txt);
    fclose($myfile);
}

?>
<html>
<head>
<script type="text/javascript">
function beforeSubmit(device_val, switch_val)
{
   document.controll.device.value = device_val;
   document.controll.switch.value = switch_val;
   document.controll.submit();
}
<?php if($_POST) { ?>
var delay = 4000; 

setTimeout(function() {
$device =  null;
   <?php if ($_POST['device'] == 'fan') {
       $device = 'Fan';
       } else if ($_POST['device'] == 'light1') {
       $device = 'Motor';
       } else if ($_POST['device'] == 'light2') {
                $device = 'Light';
       } else if ($_POST['device'] == 'light3') {
                $device = 'Light';
       }
       if($_POST['switch'] == 'on') { ?>
       document.getElementById("<?php echo $_POST['device']?>").innerHTML = '<span style="color:lime;"><b> <?php echo $device?> is On</b></span>';
   <?php } else { ?>
         document.getElementById("<?php echo $_POST['device']?>").innerHTML = '<span style="color:red;"><b> <?php echo $device?> is Off</b></span>';
   <?php } ?>
}, delay);
<?php } ?>
</script>
</head>
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top