标头功能在在线服务器上不起作用? [英] The header function is not working on online server?

查看:70
本文介绍了标头功能在在线服务器上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是不明白为什么我的代码无法正常工作.我正在为我的网站使用yahoo服务器.

hi i just dont understand why my code is not working. i am using yahoo server for my site.

这是我的注销代码.(已在localhost上成功运行),但是当我在线上载此代码时,它不起作用.请帮助

This is my logout code.(which is successfully run on localhost) but when i upload this code online then its not work. plz help

<?php  
//logout code

include("../Config.php");
if (!isset ($_SESSION['username']))
    {
header( 'HTTP/1.1 301 Moved Permanently' );
header('Location: ../index.php');

if (!headers_sent())
  { 
  header('Location: http://www.mysite.com/index.php');
  exit;
  }
    }
    else
    {

$_SESSION = array();
session_destroy();
session_unset();
header( 'HTTP/1.1 301 Moved Permanently' ); 
header('Location: ../index.php');

if (!headers_sent())
  { 
  header('Location: http://www.mysite.com/index.php');
  exit;
  }
}

?>

config.php文件包含会话代码(如启动会话)

the config.php file includes session code (like start session)

推荐答案

您需要在标头中使用完整的URI,我建议在位置标头之后立即使用exit().无需301标头即可进行简单注销. 并且请勿在php中使用结束标记.如果它在您的系统上正常运行,它看起来至少在您的一个php文件中有一些输出(也许只是一个空行)(在开始php标记之前或在结束php标记之后),并且看起来该输出在您的PHP中启用了缓冲,可以解决此错误,但是在生产服务器上禁用了缓冲.

You need to use the full URI in the header, and I recommend to use exit() right after the location header. There is no need for the 301 header for a simple log out. And don't use the closing tag in php. If it is working on your system, it looks, there is some output (maybe just an empty line) in at least one of your php files (before the starting php tag, or after the closing php tag), and it seems that output buffering is enabled in your PHP, which work around this error, but disabled on the production server.

尝试一下:

<?php
// for debugging purposes only, don't use on production server (just for debugging)
error_reporting(E_ALL);
ini_set('display_errors', 1);

//logout code

include("../Config.php");

if (isset($_SESSION['username']))
    session_destroy();

header('Location: http://www.mysite.com/index.php');
exit;

这篇关于标头功能在在线服务器上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆