PHP脚本运行两次 [英] PHP Script Running Twice
问题描述
好的,所以我有一个奇怪的问题。我有一个本地XAMPP,并且正在运行Acrylic DNS代理。在测试某些代码时,我注意到它在两次运行脚本。这就是我得到的。
Ok so I have a weird problem. I have a local XAMPP running and running Acrylic DNS Proxy as well. While I was testing some code I noticed that it was running the script twice. Here's what I got.
index.php
<?php
$myFile = "test.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "1\n";
fwrite($fh, $stringData);
fclose($fh);
?>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
AcrylicHosts.txt
127.0.0.1 test.com
127.0.0.1 *.test.com
虚拟主机文件
<VirtualHost *:80>
DocumentRoot /www/test
ServerName test.com
ServerAlias *.test.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /www/test
ServerName test.com
ServerAlias *.test.com
SSLEngine On
SSLOptions +StrictRequire
SSLEngine on
SSLCertificateFile conf/ssl.crt/server.crt
SSLCertificateKeyFile conf/ssl.key/server.key
SSLProtocol TLSv1
</VirtualHost>
如果您转到 test.com ,则text.txt输出为 1\n 1\n
If you go to test.com, the text.txt output is "1\n 1\n"
但是,如果您访问 www.test.com , text.txt输出为 1\n
But if you go to www.test.com, the text.txt output is "1\n"
任何人都知道如何使它停止运行两次?
Anyone know what to do to get it to stop running twice?
编辑:
这些是我正在使用的版本:
These are the versions I'm working with:
Apache 2.4.4
MySQL 5.5.32
PHP 5.4.19
推荐答案
这似乎是因为chrome正在寻找favicon.ico(导致404),而我.htaccess文件将所有404指向index.php文件,该文件再次执行了代码。
It looks like it was because chrome was looking for favicon.ico (which caused a 404) and my .htaccess file points all 404s to index.php file which executed the code again.
这篇关于PHP脚本运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!