douwen6274 2013-05-01 23:00
浏览 51
已采纳

PHP - 会话不会导致带标头的重定向

I am trying to make the user get redirected to the index.html page in case the $_SESSION['loggedin'] is already set. For some reason, it doesn't redirect the user, although the $_SESSION['loggedin'] when echoed returns a value.

if(!empty($_SESSION['loggedin'])) { header('Location: index.html');};

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • dongshi8038 2013-05-01 23:06
    关注

    header('Location: index.html'); sets an http header which needs to be set before any content is sent, i.e. before any echo. Also you should terminate your script after you set the location header.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 steam下载游戏占用内存
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系