doulu3399 2015-11-09 14:18
浏览 118

谷歌浏览器:会话启动时,PHP代码将执行两次

I need to set a dynamic id for every document load. This ID should be set in PHP. Now, when i set a session_start(), the php code would be executed twice because the ID-code in generated document source differs from the same code in the alerted script variable. There are no runtime errors.

What's wrong with this code and how can i prevent the session to re-execute my code after session_start() ?

And when the code would be executed twice (var idvar contains a different value) why the heck is alert executed only once?

I simplified the script so you can try for your self:

<?php

// Session start generates two different ID's
session_start();

// Create ID
$time = microtime(1);
$parts = explode('.', (string)$time);
$idvar = strtoupper(strrev(dechex($parts[0]) . dechex($parts[1]))) . dechex(rand());

?>

<script>
    // Contains a new generated ID after session_start()
    var IDvr = '<?php print $idvr; ?>';
    alert(IDvr);
</script>

Screenshots:

Alert dialog Browser Source (Chrome) of the same page!

  • 写回答

2条回答 默认 最新

  • dqq46733 2015-11-09 14:32
    关注

    Try move the id initialization just before session_start() i suspect it related on how things executed in php after session_start().

    Edit still unable to reproduce it enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题