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
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.
AAAh ...of course. Simples ! Thank you. What happens if the remote site wont allow external url calls.Does it fail gracefully or return errors?
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.
Thanks danx10 and premiumscripts. Appreciated. Sounds like a good plan. Now I just need to work out how to implement it !
@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
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....
The img tag embeds an img, however theirs no restrictions in what you insert within the img tag. By adding a php file to the img tag's value you'll just refer to the file (which is your objective?). You can read more on this technique at: http://www.davelozinski.com/scripts/random_image/index.php?1263731872590