vanlooverenkoen
vanlooverenkoen

Reputation: 2301

How to check if host is reachable on local network with php

I need to find out if a specific file, on another host, is reachable on the local network (of the client)

This is what I would like to do

<?php
function isFileReachable(){
        $urlHome = 'http://192.168.2.2/FileFolder/File.txt';
        list($status) = get_headers($urlHome);
        if (strpos($status, '404') !== FALSE) {
           return false;
        }else if(strpos($status, '200') !== FALSE){ 
            return true;
        }
}
?>

I call this script when pressing a button a my website. but I always get HTTP/1.1 301 Moved PermanentlyWhat does this mean?

Is it possible to even do this? ifso, how do I do this? What am I doing wrong? Or are there better ways to do this?

Upvotes: 0

Views: 481

Answers (1)

Javier Neyra
Javier Neyra

Reputation: 1239

look at this, https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2

its means the file you are looking for where moved to another url...

it will give you the url so you can make another request.

your code also needs to consider where the function returns false...

Upvotes: 1

Related Questions