相关文章推荐
烦恼的上铺  ·  modelscope-funasr使用web ...·  6 月前    · 
任性的消炎药  ·  matlab函数之bsxfun - ...·  1 年前    · 
坚韧的弓箭  ·  在Kotlin ...·  1 年前    · 
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"); Have you thought this through? Everyone who accesses this PHP script will see "Your license key is valid" Daan Jun 11, 2015 at 11:38 You don't appear to have set $filename it needs to be an integer higher than 0. Pretty much what the error says.... piddl0r Jun 11, 2015 at 11:38

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;
                Thank you for your comment, I find this format correct. Been programming for over 30 years. Sorry you didn't find it useful.
– user9322521
                Feb 26, 2018 at 16:14
                You're welcome to work with this formatting, but for current PHP programming, it's recommended to work with speaking variables and formatting like PSR-2. This makes code much more readable
– Nico Haase
                Feb 26, 2018 at 16:25

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.