说明: 我希望能够拥有一个系统,人们可以从我的商店购买代码,并且可以在我的PHP网站上使用该代码或密码。但每次使用该代码时,该代码的给定使用量将被下达,因此当它用完时,代码将不再可用。
示例: 我的商店正在销售一个5用户论坛的禁令代码。
该人去购买该代码并获得随机生成的饮食代码EX:91259102
此人前往兑换网站并输入购买的代码。
一旦代码被使用了一次,代码将只剩下4次使用。
一旦用户多次使用代码4,代码就不再有效了。
我希望能做什么: 通过PHP网站生成代码。 (无需自动生成)
使用MySQL数据库将给定代码存储在服务器或上的.txt文档中。
让用户能够使用我网站上的代码。
最后: 感谢您提供的任何意见,我非常感激。
谢谢,Code Squishy。
答案 0 :(得分:-2)
Do not store it in a .txt file. That's extremely insecure and just asking for someone to steal all of the codes. If you forget to blacklist that file type, anyone could simply request it and read the contents. It also would be much more difficult to deal with a TXT file than it would a database such as MySQL. This is the kind've thing databases are written for, so luckily you're covered![1]
Additionally, randomly generating would be much easier, and likely safer than generating them yourself. You could use any standard number generator, and even just hash it with the md5[2] hashing algorithm to get standard length codes.
When a new code is generated, create a new entry in your database. All the table has to contain is two columns, the code as well as the amount of uses left. Each time the code is used, just subtract from that stored value. Once it reaches zero, remove the entry from the table in your database.
PHP has many constructs for accomplishing all of these. This is where I recommend you start: [1]MySQL and PHP
我希望这有帮助!