【问题标题】:PHP Script Running TwicePHP 脚本运行两次
【发布时间】:2013-11-14 16:20:59
【问题描述】:

好的,我有一个奇怪的问题。我有一个本地 XAMPP 正在运行并运行 Acrylic DNS 代理。当我测试一些代码时,我注意到它运行了两次脚本。这是我得到的。

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

但是如果你去 www.test.com,text.txt 的输出是“1\n

有谁知道如何让它停止运行两次?

编辑:

这些是我正在使用的版本:

Apache 2.4.4
MySQL 5.5.32
PHP 5.4.19

【问题讨论】:

  • 试试这个,然后.. $ curl test.com/index.php
  • 我相信 test.com 调用了两次,这是运行 index.php 的默认行为。如果 test.com 访问两次,请检查您的 access_log。这里可能会发生重定向问题
  • 我的访问日志显示 "GET / HTTP/1.1" 200 466 "GET /favicon.ico HTTP/1.1" 404 1067 "GET / HTTP/1.1" 200 466 你认为这可能是因为404?

标签: php apache .htaccess xampp


【解决方案1】:

看起来是因为 chrome 正在寻找 favicon.ico(导致 404),而我的 .htaccess 文件将所有 404 指向 index.php 文件,该文件再次执行了代码。

【讨论】:

  • 请将此标记为答案。这可能会对面临同样问题的人有所帮助。
  • 等等,那个.htaccess在哪里,我也有同样的问题,这就是答案
猜你喜欢
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-07
  • 1970-01-01
  • 2020-09-29
  • 1970-01-01
相关资源
最近更新 更多