SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Machine Information

    Hi Guys.

    I was just wondering is it possible to get the machine name via PHP or Javascript. The reason i ask is that I want to bring up custom webpages via mahcine name. Its for an internet cafe so that I can log into an internal webserver, it will get the machine name and bring up relative information. I just want to know if its possible.

    Dave
    Its only a mistake if you repeate it.

  2. #2
    SitePoint Zealot dawgbone's Avatar
    Join Date
    Dec 2003
    Location
    Brampton
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why not just go by ip address?

  3. #3
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *Ding ding ding*

    Dawgbone, you advance to the lightning round!



    Seriously though, assuming all computers in the cafe will be set on static IPs all you would need to do is something like this.

    PHP Code:
    //-- index.php

    //-- Setup an array of different IPs and the page they need

    $cafe_computers = array(
            
    "2" => "192.168.0.2",
            
    "3" => "192.168.0.3",
            
    "4" => "192.168.0.4",
            
    "5" => "192.168.0.5");

    //-- Check to see which machine the request for 
    //-- index.php is coming from and include the
    //-- necessary page


    //-- Loop through the list of computers
    foreach ( $cafe_computers as $computer){
              
    //-- Check to see if this machine is in our list
              
    if( $REMOTE_ADDR == $computer){
                    
    //-- Replace the periods in the IP
                    //-- addresses with underscores
                    
    $page str_replace(".""_"$computer);
                    
    //-- Give them the proper page
                    
    include_once("$page.php");
             }else{
                    
    //-- We make the script die so that they get redirected to 
                    //-- an error page or whatever...
                    
    die("No Page For You!!!");
             }
    //end If
    }//End foreach 
    I didn't test this but I think it will work.
    Last edited by maxor; May 27, 2004 at 00:21.

  4. #4
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are looking for hostnames in stead of machinenames you might use something like this:

    PHP Code:
    <?php
    $host 
    gethostbyaddr($_SERVER['REMOTE_ADDR']);
    $host preg_replace("/^[^.]+./""*."$host);
    ?>

  5. #5
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    According to jz at NOSPAM dot nplu dot kiev dot ua on PHP.net:

    Quote Originally Posted by jz at NOSPAM dot nplu dot kiev dot ua

    Just to fun that gethostbyadd() returns server machine name known in LAN rather then its DNS if I try to call it against my own host (from workstation), whether it would local (behind the proxy) or global (of proxy itself) IP or just loop 127.0.0.1.

    And thus you can get LAN names of other workstations by its intranet IPs (I mean smth like 192.168.0.???)

    Fun


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •