Protect PHP script to run ONLY 1 Domain name - How???

Discussion in 'PHP' started by fdoze, Mar 3, 2009.

  1. #1
    Hi,


    how can I set a php script just to run from specific domain name?

    How is the best way to protect php code using this method?

    Can anyone give me a script to this? some snippet?




    Thanks in advance.
     
    fdoze, Mar 3, 2009 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    zend encode your script and check server settings ;)
     
    EricBruggema, Mar 3, 2009 IP
  3. PHP_Adam

    PHP_Adam Guest

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Unless you encode the script, the person will be able to remove your line of code and use the website as they wish.

    You could encode the an important include file for example.

    You could use $_SERVER["SCRIPT_URI"] to detect the domain name used.

    Something like this may work?
    if(!ereg("yourdomain.com",$_SERVER["SCRIPT_URI"]){ die("Invalid Domain"); }
    PHP:
     
    PHP_Adam, Mar 3, 2009 IP
  4. jackisyourcontractor

    jackisyourcontractor Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In your form processing script, use the server variable for host. The following line gives some idea of how you would use it:

    $whatSiteIsSubmittingThis = $_SERVER['HTTP_HOST'];

    The variable $whatSiteIsSubmittingThis will show the main URL of the site that is sending the posted data. It will appear in "www.<your domain name>.com" format. Then just do a simple compare, for example:

    if ($whatSiteIsSubmittingThis = "www.google.com"){
    //do your stuff
    }else{
    die('Hey! I only accept form submissions from my own site!');
    }

    Just get in touch if you need more help!
     
    jackisyourcontractor, Mar 3, 2009 IP
  5. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    But may I protect that lines of code from being deleted?


    Or could I delete importante files on server if wrong domain name?


    Thanks.
     
    fdoze, Mar 3, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    In some countries, that could land you in prison.
     
    SmallPotatoes, Mar 3, 2009 IP
  7. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Make sure you put == instead of =, otherwise it will always evaluate to true.

    if ($whatSiteIsSubmittingThis == "www.google.com"){
    //do your stuff
    }else{
     die('Hey!  I only accept form submissions from my own site!');
    }
    PHP:
     
    qualityfirst, Mar 3, 2009 IP
  8. Steve_D

    Steve_D Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    invest in one of the PHP source encoder products or you could base64_encode the source, but it would be easy to decode it , you can try this online at makcoder.sourceforge.net/demo/base64.php

    do a search on G for php file encode or similar and it will chuck up a few choices.
     
    Steve_D, Mar 3, 2009 IP
  9. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    What could be the best PHP encoder?

    every encoder could code to specific domain name of my choice?

    Thanks.
     
    fdoze, Mar 3, 2009 IP