dq_1984 2012-09-20 19:01
浏览 82

Php文件使用htaccess重定向执行2次

I have htaccess file which contain:

RewriteRule . index.php [L]

index.php:

mysql_query("UPDATE users SET Views = Views + 1 WHERE SteamID = '" . mysql_real_escape_string($steamid) . "'", $db);

When I opening index.php, mysql_query executes 2 times, and column Views every time increases in 2. Why?

added:

I made test.php with content:

<?
$db = mysql_connect('localhost', '****', '******');
mysql_select_db("*****", $db);
mysql_query("UPDATE users SET Views = Views + 1 WHERE SteamID = '76561198037192367'", $db);
?>
loaded

this code is executing 3 times!! when I delete .htaccess everything is working properly. It's really strange...

  • 写回答

2条回答 默认 最新

  • dongwen3410 2012-09-20 19:08
    关注

    The rules aren't directly causing the index.php file to get loaded twice. There's probably something in index.php, or the HTML content that is returned, that makes the browser load something (like an image, script, style, etc?) that the rule is catching and rewriting back to index.php. This makes it so when you load a page in a browser that gets routed to index.php, index.php actually gets ran twice.

    You're either going to have to modify the HTML content that index.php outputs, modify the index.php script so that the query only gets executed when specific _SERVER['REQUEST_URI']'s are requested, or add restriction conditions to the RewriteRule . index.php [L] rule so that it only loads once.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法