dongxunhua2054 2014-03-20 20:30
浏览 22
已采纳

PHP GET变量测试

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

  • 写回答

2条回答 默认 最新

  • donglu1881 2014-03-20 20:35
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大