Run php localhost file from the server

0

My file located in my localhost is called datos_pc.php , it is the one that contains the name of the PC and the MAC, which I need to keep record of activities by computer, for this I have the file with the data in a% % co:

<?php
header('Access-Control-Allow-Origin: *');

$array = array(
    'pc_name' => 'DESKTOP-RS4KBQP',
    'pc_mac' => 'D4-85-64-16-20-06'
    );
echo json_encode($array);
?>

And to access from the server to this file that is in each computer I use this function:

$file = 'http://127.0.0.1/unicos/datos_pc.php';
$file_headers = @get_headers($file);

if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
  echo '  nooooo existe ';
}
else {
    $data = file_get_contents($file);
    $data = json_decode($data, true);
    echo $data['pc_name'];
}

But does it always return a Array message, did someone do something similar? thank you very much !!!

    
asked by jantoni 01.07.2017 в 17:35
source

3 answers

0

yes but this address is incorrect (http://127.0.0.1/unicos/datos_pc.php) this points to your localhost of your PC (if you are on the server will still point to it) if you want to connect to a computer on the network you must first have the fixed ip of the network lan and have a web server on that computer for communication by http: Example:

http://192.168.100.12/unicos/datos_pc.php

on the remote computer you need to have xampp installed and with the folder and file:

/unicos/datos_pc.php

in this way the only thing that can interfere: firewall, read permissions.

You can also change the computer to read it as a plain text file remotely as a shared file.

    
answered by 01.07.2017 / 17:53
source
0

Take a look at the available documentation $ _SERVER depends what data you want to identify the team from which they connect; (in English) will help you How can I get the MAC and the IP address of a connected client in PHP? .

Luck.

    
answered by 01.07.2017 в 19:17
0

The simplest solution was to do it with a language from the client, in this case JavaScript, with this function

$.ajax({
type: "POST",
url: "http://127.0.0.1/unicos/datos_pc.php",
async:true,
dataType: "json",                      
data: {},
beforeSend: function() {

},
success: function(data){
  $('#hdd_vista_pc_nombre').val(data.pc_name);
  $('#hdd_vista_pc_mac').val(data.pc_mac);
  console.log('nombre de equipo: ' +data.pc_name);
},
complete: function(data){
  if(data.statusText != "success"){
    $('#msj_nombre_mac').show(100);
    $('#msj_nombre_mac').html("No se pudo obtener los datos de la PC, por favor actualiza o comunicate con sistemas");
  }
}

});

    
answered by 01.07.2017 в 19:21