dplm47571 2014-10-03 21:41
浏览 40
已采纳

为什么我使用相同的代码得到会话错误? [重复]

This question already has an answer here:

I have 3 type of forms on my web site and all worked fine until one day. I don't know what happened but I'm getting session errors; by this I mean I get an error whenever I have a PHP script that include the session tag inside it for example this is on my start over the <html> tag:

<?php

// Make the page validate
ini_set('session.use_trans_sid', '0');

// Create a random string, leaving out 'o' to avoid confusion with '0'
$char = strtoupper(substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 4));

// Concatenate the random string onto the random numbers
// The font 'Anorexia' doesn't have a character for '8', so the numbers will only go up to 7
// '0' is left out to avoid confusion with 'O'
$str = rand(1, 7) . rand(1, 7) . $char;

// Begin the session
session_start();

// Set the session contents
$_SESSION['captcha_id'] = $str;

?>

When I test this on my website I get:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home4/domain/public_html/adres/contact.php:2) in /home4/domain/public_html/adres/contact.php on line 16

Exactly the part where the session_start() is ? The same code structure worked before - what happened?

</div>
  • 写回答

2条回答 默认 最新

  • du7999 2014-10-03 21:46
    关注

    Check if you have any spaces or newlines before your opening <?php tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探