Human or Server?

Discussion in 'PHP' started by Kennedy, Feb 26, 2008.

  1. #1
    I am trying to get a script to only work if someone's server is accessing it. I don't want it to work if they try to load it up in their browser.

    Is there any way to do this?

    Thanks in advance!
     
    Kennedy, Feb 26, 2008 IP
  2. PHPGator

    PHPGator Banned

    Messages:
    4,437
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    260
    #2
    I personally don't know of a sure fire way to do this, but I do know that you can check for what browser the person is using and you could cut out access if they are using any of the major ones. This would probably not allow 95%+ of traffic from browsers if not more.
     
    PHPGator, Feb 26, 2008 IP
  3. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can check the apache environement variable HTTP_USER_AGENT

    But why do you need to allow servers and not humans? (then just don't give the url...)
     
    selling vcc, Feb 26, 2008 IP
  4. Kennedy

    Kennedy Peon

    Messages:
    994
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I need to give the URL so they can access it with their servers without them seeing it.

    Basically for-machine-eyes only. I have some powerful code that I want to sell, but I don't want it altered or pirated.
     
    Kennedy, Feb 26, 2008 IP
  5. blogo

    blogo Peon

    Messages:
    113
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can try this code ...

    <?php
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
    {
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') )
    {
    $browser = 'Netscape (Gecko/Netscape)';
    echo 'You Are Not Allowed To See This Page';
    }
    else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') )
    {
    $browser = 'Mozilla Firefox (Gecko/Firefox)';
    echo 'You Are Not Allowed To See This Page';
    }
    else
    {
    $browser = 'Mozilla (Gecko/Mozilla)';
    echo 'You Are Not Allowed To See This Page';
    }
    }
    else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
    {
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
    {
    $browser = 'Opera (MSIE/Opera/Compatible)';
    echo 'You Are Not Allowed To See This Page';
    }
    else
    {
    $browser = 'Internet Explorer (MSIE/Compatible)';
    echo 'You Are Not Allowed To See This Page';
    }
    }
    else
    {
    $browser = 'Others browsers';
    //Run your Code here
    }

    ?>

    This code is not full proof .. you can load some sessions to be more confirmed.

    You can also check operating systems....
     
    blogo, Feb 27, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    There's no way to figure this out. People could just use a proxy, which would go in the category of "servers".

    Anyway, if you want to make sure it's a server (or proxy) use:
    
    if (!@fsockopen($_SERVER['REMOTE_ADDR'], 80))
    {
        header('HTTP/1.1 401 Unauthorized');
        exit('Unauthorized access');
    }
    
    PHP:
    Should work in most cases.
     
    nico_swd, Feb 27, 2008 IP
  7. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #7
    Even with a proxy, it could be be easily bypassed. Considering if someone wants to see the code, they will. With FireFox, you can easily download a plug-in that will let FF report as any browser (or any server) you want.

    Is your script reporting back information about its existence?

    Bing
     
    bpasc95, Feb 27, 2008 IP
  8. Kennedy

    Kennedy Peon

    Messages:
    994
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yes. I fully understand that no lock is perfect. But the data will be encrypted in 2 ways, need a key to be accessed completely, and send me an email when its run giving me the details of the domain so I can watch it for activity.

    Still always hackable, but I just don't want to make it easy on them.
     
    Kennedy, Feb 27, 2008 IP
  9. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #9
    forget checking user agent's, it's the poisened and unreliable env ever. 99.9% of browser send some or all of the following:
    [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_ACCEPT_LANGUAGE] => en-gb,en;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip,deflate
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7

    however servers will almost never send them, specifically HTTP_ACCEPT_LANGUAGE and HTTP_ACCEPT_CHARSET, if they are present odd's are it's a standard user(_agent).
     
    blacknet, Feb 27, 2008 IP
  10. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Theres a simpler way which will probably work.

    Send a redirect header before your content.

    Browsers will obey, standard socket clients wont.
     
    able, Feb 27, 2008 IP