树莓派python向php发送get请求,php接收数据并显示

树莓派python向php发送get请求,php接收数据并显示

1.树莓派端代码

import requests
import time
a=1
while True:
a=a+1
url = ‘http://192.168.31.174/index.php?id=’+str(a)
response = requests.get(url)
print(response.status_code)
print(response.text)
time.sleep(1)

2.php端代码

在服务器上需要操作权限,所以先使用命令创建1.txt:sudo touch 1.txt
再更改1.txt的操作权限:sudo chmod 0666 1.txt

<?php
	if($_GET["id"]>"0"){
	$myfile = fopen("1.txt", "w") or die("Unable to open file!");
        fwrite($myfile, $_GET["id"]);
        fclose($myfile);}       
        $myfile = fopen("1.txt", "r") or die("Unable to open file!");
	echo fread($myfile,filesize("1.txt"));
	fclose($myfile);
	echo ("<script>setTimeout('window.location.reload()', 1000);</script>");
?>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值