[英]PHP: IP address Check in text file
I've been trying to grab a person's ip-address and then store it in a txt file when a person pays me to access certain content. 我一直试图获取一个人的ip地址,然后在有人向我付款以访问某些内容时将其存储在txt文件中。 When I store the IP in the txt file (logFile.txt), I want the person that paid the fee to be redirected to a content page that is only available for the people that have payed.
当我将IP存储在txt文件(logFile.txt)中时,我希望将支付费用的人重定向到仅对支付者可用的内容页面。 I also want to be able to redirect people that try and copy/paste the browser link to the "extra content".
我还希望能够将尝试将浏览器链接复制/粘贴到“其他内容”的用户重定向。
I have code in my in my site that can log people's ip-address, but i want take that log file and cross reference it with the extra content page. 我的网站上有代码可以记录人们的ip地址,但是我想获取该日志文件并将其与额外的内容页面进行交叉引用。
ps i've spent hours trying to figure this out with logging it to a text file to avoid mysql PS我花了几个小时试图解决这个问题,将其记录到文本文件中以避免mysql
I just need a general idea so i can wrap my head around this thing. 我只需要一个一般的想法,这样我就可以把这个问题包扎起来。 not sure how to go about doing all this.
不知道该怎么做。
$_SERVER['REMOTE_ADDR']
to get the user's IP address and file_put_contents to write it to a file, but I'm not certain the way you're going about this is the best way. $_SERVER['REMOTE_ADDR']
获取用户的IP地址,并使用file_put_contents将其写入文件,但是我不确定您打算采用的方式是最好的方法。 You can store the IP addresses in an array: 您可以将IP地址存储在数组中:
array{
[0] => '192.168.1.1',
[1] => '192.168.1.2',
}
Then before saving to your text file, use serialize on the array. 然后,在保存到文本文件之前,请在阵列上使用序列化 。 This will return a string that you can write to your text file.
这将返回一个字符串,您可以将其写入文本文件。
To retrive your array, just use unserialize to get the array back. 要检索数组,只需使用反序列化即可将数组取回。 Now, you should have an array of IP addresses which you can use the standard array functions to search, add and delete from.
现在,您应该拥有一个IP地址数组,可以使用标准的数组功能来搜索,添加和删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.