Hello Dear Friends,


Consider we have an php file called

index.php

how can i add a code to (index.php) so that when it excute (run) on any website for example (anysite.com)

it call an text file (license.txt) which is on my server and also in same time it record the URL of the (index.php) in another text file (record.txt)


WHAT FOR


it someone open ( index.php) it will record in a text file on my server the URL
if it was licensed then it will be okay and if not
then i remove the ( license.txt) and then index.php won't work


I've made the following code but it give some problems


on my server both
track.php and empty counter.txt

<?php
$url = @$_GET['url'];
$path = @$_GET['path'];
$entry_line = "$url | $path
"; //give ENTER to break into new line in text file
$fp = fopen("counter.txt","a");
fputs($fp,$entry_line);
fclose($fp);
?>

and the tacking code inside index.php

$f = @fopen("xxxxxxxxxxxxxxxxxxx/track.php?url=$_SERVER[HTTP_HOST]&path=$_SERVER[SCRIPT_FILENAME]","r");
@fread($f,10);
@fclose($f);

where xxxxxxxxxxxxxx is my website which i do stored the text file


PROBLEMS

1- It makes the website running so slow
2- it keeps store the URL everytime it open i mean has no overwrite option if same URL

My needs

any simple idea that makes me able to do the following

- know what url using the script ( index.php )
- if i changed license.txt , it won't load ( index.php ) or give warrning MSG not licensed please buy license


thanks in advance

it really will helps me a lot

The quick answer is that it can't really be done, because you cannot guarantee that fopen is allowed to open external URLs. My webhost, for example, do not allow this. I expect many (possibly most) webhosts act in the same way.
See here for their explanation: Pipeten - allow_url_fopen=Off

The alternative is Curl, but I don't think every webhost has Curl installed, so unless you put that as a requirement of running the software, you wouldn't be able to do it. You can find out more about Curl here: PHP manual - Curl

I'm sorry I've not really given an answer as to how you can resolve your problem, but I don't think reading a file from your server is the best solution.

This is kind of pointless, because anyone with a little knowledge of php can easily go in and remove the part of the code that checks if the page is licensed or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.