"call home to check" script

Discussion in 'PHP' started by deemainer, Jan 16, 2010.

  1. #1
    Hi all,

    Looking for a headstart on a call home script. Basically php script that can be embedded in a wordpress footer theme for example and lets the author know what websites are using the template. Possibly even then pulls a link from remote site to display in template.

    Anyone know how to do this please? Guess it would be relatively easy to pull a link with curl or file get contents from a remote site, but how about the letting remote url know the site is using the template?

    Thanks in advance
     
    deemainer, Jan 16, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    One way is to log referers too a specific file which you'd use on your themes:

    Put this on your themes:
    <?php
    //added @ to supress errors
    if (function_exists('fopen') && function_exists('fclose')) {
    //your site
    $fp = @fopen('http://www.yoursite.com/callback.php', 'r');
    @fclose($fp);
    }
    ?>
    PHP:
    Put this on your site (e.g. http://www.yoursite.com/callback.php):
    <?php
    if(!$_SERVER['HTTP_REFERER']){
    echo "No direct access!";
    
    } else {
    
    $logfile= 'log.html';
    if(is_writable($logfile)) {
    $referer = parse_url($_SERVER['HTTP_REFERER']);
    $referer = $referer['host'];
    $fp = fopen($logfile, "a");
    fwrite($fp, $referer);
    fwrite($fp, "<br>");
    fclose($fp); 
    } else {
    echo "log.html is not writable";
    }
    
    }
    ?>
    PHP:
    This will save all sites which use your theme/s and list them within a html file called log.html.
     
    Last edited: Jan 16, 2010
    danx10, Jan 16, 2010 IP
  3. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #3
    AAAh ...of course. Simples ! Thank you.

    What happens if the remote site wont allow external url calls.Does it fail gracefully or return errors?
     
    deemainer, Jan 16, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    I've updated my post so it should fail gracefully. :p
     
    danx10, Jan 16, 2010 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you're only doing it to find out what sites are using your theme, you should probably create a new wp option after the first time. From then on simply check to see if the wp option exists or not, if it exists the call has already been made and you needn't connect any more. The reason for doing this is that the site that is using your theme would otherwise be slowed down unnecessarily.

    I'm not sure if wp themes can have an activation/installation function like wp plugins, but if they can it would be even better to put the code in that function.
     
    premiumscripts, Jan 16, 2010 IP
  6. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #6
    Thanks danx10 and premiumscripts. Appreciated.


    Sounds like a good plan. Now I just need to work out how to implement it ! :)
     
    deemainer, Jan 17, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    @deemainer && premiumscripts.

    The code to insert within the wordpress theme doesnt neccesarily have to use the fopen function (although effective), theirs other way you could even do this for example:

    <img src="http://www.yoursite.com/callback.php">
    Code (markup):
    Aslong as you connect to your site, it don't matter what method you use. (If you use the img tag you could use css to hide it).

    You could also use cURL and fsockopen().

    So theirs an array of solutions their for you and following:

    The reason for doing this is that the site that is using your theme would otherwise be slowed down unnecessarily. 
    Code (markup):
    You could add an if statement so the code only connects upon the wp installation date
     
    Last edited: Jan 17, 2010
    danx10, Jan 17, 2010 IP
  8. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #8
    Wow. I had no idea you could do that ! And would referencing a php file as an image actually run the file ?

    I guess it probably would as all the file knows is that its being called....
     
    deemainer, Jan 17, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    danx10, Jan 17, 2010 IP
    deemainer likes this.
  10. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #10
    thanks for your help.
     
    deemainer, Jan 17, 2010 IP