Trying to do something that should be very easy but not for me. I am trying to pass a variable thru a $_GET to php and store it in a text file. The variable ip is posted from an external source. I have the following: The xxx represent the ip address
$myFile = "http://xxx.xxx.x.x/iploc.txt";
$var1 =$_GET['ip'];
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $var1);
fclose($fh);
I have tried to test this by entering http://xxx.xxx.x.x/iploc.php?ip=1234 into my web address bar to see what happens. It displays the iploc.php content and does not save the ip to the text file. I know little about doing this so be kind. By looking at my server access log it seems to be getting there. Thanks in advance
On the server you want to write the files make this php script :
<?php
if($_SERVER['REMOTE_ADDR'] == 'xx.xx.xx.xx'){ //replace xx.xx.xx.xx by the IP of the server sending the IPs addresses
file_put_contents('iploc.txt', $_GET['ip'], FILE_APPEND);
}
?>
Now on the external server, call this url like that :
file_get_contents('http://myserver.com/script.php?ip=xx.xx.xx.xx');
It displays the iploc.php content and does not save the ip to the text file
Sounds to me as if the PHP code is not parsed by the server where you are trying to run the code. Is PHP activated and running?