【发布时间】:2020-08-29 15:45:44
【问题描述】:
我对在 PHP 站点中包含 Python 还是很陌生。我正在创建一个 Python 闹钟,女巫应该打开位于我的 PC 上的不同网页。我有一个 PHP 页面,它会在启动时自动打开,我可以在其中花时间醒来。当我按“保存”时,它应该启动 python 文件,然后应该打开另一个页面并启动时钟。我现在的问题是起始页面无限加载并且没有任何反应。我做错了什么。
我的代码如下:
index.php:
<?php
if(isset($_POST['submit'])){
$Name = "".$_POST['username']."
";
$Pass = "".$_POST['password']."
";
$file=fopen("saved.txt", "a");
fwrite($file, $Name);
fwrite($file, $Pass);
fclose($file);
$command = escapeshellcmd('python /home/lul/Desktop/wecker.py');
$output = shell_exec($command);
echo $output;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="styles.css">
<title>My HTML Form</title>
</head>
<body class="blogdesire-body">
<div class="blogdesire-wrapper">
<div class="blogdesire-heading">
My HTML Form
</div>
<form class="blogdesire-form" method="post">
<input type="number" name="username" placeholder="Hour" required autocomplete="off"> <br>
<input type="number" name="password" placeholder="Minutes" required autocomplete="off"> <br>
<input type="submit" name="submit" value="SAVE" class="blogdesire-submit">
</form>
</div>
</body>
</html>
python 代码:
#!/usr/bin/python
import webbrowser
import datetime
import os
print('Try opening file')
fileHandler = open ("/var/www/html/saved.txt")
listOfLines = fileHandler.readlines()
fileHandler.close()
hours = int(listOfLines[0])
minutes = int(listOfLines[1])
print(hours, minutes)
print(datetime.datetime.now().hour, datetime.datetime.now().minute)
os.remove("/var/www/html/saved.txt")
webbrowser.open("file:///home/lul/Desktop/startup/clock.html")
print("Done Opening")
while (1 == 1):
if (hours == datetime.datetime.now().hour and minutes == datetime.datetime.now().minute):
webbrowser.open("file:///home/lul/Desktop/morning/morning.html")
print('Sup')
【问题讨论】: