JOAOSANTACRUZ.COM

How to share your localhost pages with in the internet

Know your home ip address from anywhere. Access your HomeServer localhost

How to get your home server IP address?



1. In your server, set a

cron

to periodically run local "set-my-ip.php" script


This will send your actual IP address to a server that is allays ON (ex:

dev.joaosantacruz.com

).



2. Point your OnlineServer (ex:

dev.joaosantacruz.com

) to "get-my-ip.php" script


This will redirect you to the actual local IP address and show your localhost content.




NOTE: Don't forget to make the appropriate changes if you're behind a router. Some tricks like port-forwarding may be considered.





set-my-ip.php

<?


file_get_contents('

http://dev.joaosantacruz.com/?key='.base64_encode(

"my-super-key") . '&local=' . $_SERVER["SERVER_ADDR"]);


?>






get-my-ip.php

<?php


// = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =


//                     IP ADDRESS UPDATE/REDIRECT  [ ONLINE SERVER ]


// = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =  = =


//CHECK KEY AND UPDATE IP ADDRESS



if(base64_decode($_GET["key"])

=="my-super-key"){
   
    file_put_contents("remote.address", $_SERVER[REMOTE_ADDR]);
    file_put_contents("local.address", $_SERVER[REMOTE_ADDR]);
   
}else{ //REDIRECT TO THE STORED IP ADDRESS (CHECK IF IS LOCAL REQUEST)

        $server = file_get_contents("remote.address"); 
        $local  = file_get_contents("local.address");
       
       
        if($_SERVER[REMOTE_ADDR]==$server)
            header("location: http://$local/");
        elseif(!$server)
            die("<center>No ip address defined!!</center>");
        else
            header("location: http://$server/");

}

?>
Go Back