Reputation: 11
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. 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. 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.
p.s. i've spent hours trying to figure this out with logging it to a text file to avoid 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.
Upvotes: 1
Views: 925
Reputation: 26502
$_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.Upvotes: 4
Reputation: 33391
You can store the IP addresses in an array:
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.
Upvotes: 1