开发者

The header function is not working on online server?

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

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 Permanent开发者_运维技巧ly' );
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;
  }
}

?>

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


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.

Try this:

<?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;


  echo '<script type="text/javascript">
    function delayer(){
     window.location = "../index.php"
 }
 setTimeout("delayer()", 1000);

   </script>';

You could put this instead of header


This will work

<script type="text/javascript">
  window.location="http://www.newlocation.com"; 
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜