-1

嗨,我只是不明白为什么我的代码不起作用。我正在为我的网站使用雅虎服务器。

这是我的注销代码。(在本地主机上成功运行)但是当我在线上传此代码时它不起作用。请帮助

<?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 文件包含会话代码(如启动会话)

4

3 回答 3

1

您需要在标头中使用完整的 URI,我建议在 location 标头之后使用 exit()。简单的注销不需要 301 标头。并且不要在 php 中使用结束标记。如果它在您的系统上运行,它看起来,在您的至少一个 php 文件中(在起始 php 标记之前,或在结束 php 标记之后)有一些输出(可能只是一个空行),并且似乎输出在您的 PHP 中启用了缓冲,可以解决此错误,但在生产服务器上禁用。

试试这个:

<?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;
于 2010-11-15T12:34:09.757 回答
0
  echo '<script type="text/javascript">
    function delayer(){
     window.location = "../index.php"
 }
 setTimeout("delayer()", 1000);

   </script>';

你可以把这个代替标题

于 2013-04-10T14:46:14.997 回答
0

这将起作用

<script type="text/javascript">
  window.location="http://www.newlocation.com"; 
</script>
于 2014-01-10T13:30:32.890 回答