Page validation with PHP and JAVASCRIPT

Asked

Viewed 38 times

-2

So I do computer networks and I’m the last semester, we’re doing a TCC where it will work as follows:

A Mesh network for remote areas that do not have internet access, so whoever is connected to this network will be able to watch movies, listen to music, talk via text and voice, etc.

I am tasked with creating a community page where the staff will access the link and will have the button of the applications that will be redirected to the application and the problem is there.

I need to perform the validation to see if the IP/ DNS is in the air or not, but doing this in the front end is not 100% sure because it has several contradictory because an offline web page can be several things that only emits an HTTP, so I’m doing it in PHP, but I’m not able to perform the "merge" of javascript with PHP, see:

Calling on Function Javascript:

            document.getElementById('plex').addEventListener('click', () => checagemplex());

Function:

            function checagemplex () {
            var checar = <?php
                if (!fsockopen("192.168.1.145", 80, $errno, $errstr, 10)) {
                    echo "Offline";
                } else {
                   echo "Online"; 
                }
            ?>;

            $.ajax({
                checar;
            }).done(function() { 
                alert('Online');
            }).fail(function() { 
                alert('Offline');
            })
        }

Has anyone ever been in this situation and knows some way to improve the checking function and make it work?

Thank you!

  • I believe that the best way would be for you to use a ping: https://answall.com/questions/158466/usando-ping-comphp

1 answer

-1

I even tried to do it that way:

        <input type="button" value="TESTE" id="buttonx">
    <script>
        function checkplex () {
            var check = <?php 
                    exec('ping 127.0.0.1', $saida, $retorno);
                    if (count($saida)) {
                        print 'A Máquina está online e os dados do PING foram gravados em $saida. :)';
                    } else {
                        print 'A Máquina NÃO está online ou o host não pode ser encontrado. :(';
                    }
                ?>
            document.write(check);  
        }
        document.getElementById('buttonx').addEventListener('click', () => checkplex());
    </script>

Even so, it didn’t work, the button call I can only do in client-side need to make this combination of PHP with JS, rs.

Thanks for the strength, but I still can’t I’m researching and see if I find something

Browser other questions tagged

You are not signed in. Login or sign up in order to post.