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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊