Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

apache - PHP Script Running Twice

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
";
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

Vhost File

<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>

If you go to test.com, the text.txt output is "1 1 "

But if you go to www.test.com, the text.txt output is "1 "

Anyone know what to do to get it to stop running twice?

Edit:

These are the versions I'm working with:

Apache 2.4.4
MySQL 5.5.32
PHP 5.4.19
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...