Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to create a system with license with my own code,but gives me an error
the code is like this and in lic.txt is the same 1234567,what is wrong?
This is the error,if i put @ in front of fread dosent show the error but does not open the file
Warning: fread(): Length parameter must be greater than 0 in /home/u422978792/public_html/platforma/license/index.php on line 7
Invalid license key
$fp = fopen("http://platforma.dar-project.org/license/lic.txt", "r");
stream_set_timeout($fp, 10);
$license = fread($fp, filesize($filename));
fclose($fp);
if ($license == "1234567") {
echo "Your license key is valid";
} else {
die("Invalid license key");
–
–
PHP will return warnings and/or errors if the file doesn't exist (maybe it's mis-spelled or a malformed URL) or if the file-size is 0 bytes.
Here is a small function that verifies and returns either the file content in a string, or will return a "-1", in which case you know there was a problem while reading.
$file_content = ReadtextFile( "file.txt" ); // caller
function ReadtextFile($FileName)
if (file_exists($FileName) )
$file_size = filesize($FileName);
if ($file_size == 0) return "";
else return "-1";
if (!$fp = fopen($FileName, "r")) return "-1";
$s01 = fread($fp, filesize($FileName));
fclose($fp);
return $s01;
–
–
your file lic.txt
should be empty. Therefore, fread()
can not read anything from the file.
and hence your condition leads to echo 'Invalid license key'.
one suggestion ,I have come across this problem when runing a opencart website,
my solution is increasing the size of disk for the domain. OR Delete unnecessary items from your file manager of your Cpanel of your domain.
hope will help
$myfile = fopen("webdictionary.txt", "r") or
die("Unable to open file!");
$len =filesize("webdictionary.txt");
echo "File content lenths:- $len .<br>";
echo "file containt.<br>";
for ($i=0;$i<$len;$i++)
echo fgetc($myfile);
echo "<br>";
fclose($myfile);
echo "$myfile";
return -1;
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.