0

Hello,

I have two copies of the same website: one in the localhost and one is online. My offline website generates error after I login to the admin page:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\xampp\htdocs\rustoleum\administrator\admin.php:9) in C:\xampp\xampp\htdocs\rustoleum\administrator\admin.php on line 52

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\rustoleum\administrator\admin.php:9) in C:\xampp\xampp\htdocs\rustoleum\administrator\admin.php on line 56

admin.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Rustoleum Admin Page</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="rustoleum, coating" />
<meta name="description" content="Rustoleum Indonesia provides coating solution for industrial requirement and individual needs." />

<style type="text/css">
#slideshow { left: 35px; float: left; margin: 10px; z-index: 0;}
#nav { width: 270px; margin: 170px 0 0 225px; float: left; position: absolute; z-index: 1;}
#nav li { float: left; margin: 0 0 0 4px; list-style: none; background: url(images/pager3-2.jpg) no-repeat top;}
#nav a { width: 40px; padding: 3px; display: block; border: 1px solid #ccc;}
#nav li.activeSlide a { /* background: #88f */ background: url(images/pager3.jpg) no-repeat top;}
#nav a:focus { outline: none;}
#nav img { border: none; display: block;}
pre { clear: left }
</style>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/chili-1.7.pack.js"></script>
<script src="../js/jquery.cycle.all.js" type="text/javascript"></script>
<script src="../js/jquery.easing.1.3.js" type="text/javascript" ></script>
<link href= "../css/admin.css" rel="stylesheet" type="text/css" media="screen">
<link href= "../css/navstyleadmin.css" rel="stylesheet" type="text/css" media="screen">
<script type="text/javascript">
$('#slideshow').cycle({ 
    fx:     'fade', 
    speed:   900, 
    timeout: 10000, 
    pager:  '#nav', 
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav li:eq(' + idx + ') a'; 
    } 
});
</script>



</head>

<div id="main-wrap">
<body>

<?php

// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.

session_start();

if(!isset($_SESSION['username']))
    {
    header("location:index.php");
    }

?>

line 52: session_start();

line 56: header("location:index.php");

How to fix the error? Is it a normal thing for offline website? (since my online website doesn't show error)

4
Contributors
7
Replies
36
Views
3 Years
Discussion Span
Last Post by Borzoi
0

The header(); function also needs to be before any output to the browser, if I'm not mistaken.

You basically just wamt to move the PHP in your code (lines 46-58 in the code you've given) to the top of the page, before the <!DOCTYPE> declaration.

I also recommend you put exit; after the header, within the same if statement because without it, the rest of the code will still run.

0

I place this code on the top:

<?php

// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.

session_start();

if(!isset($_SESSION['username']))
    {
    header("location:index.php");
    }

exit;
?>

Everything works fine, except that I cannot login. I can only login if I delete this code:

if(!isset($_SESSION['username']))
        {
        header("location:index.php");
        }

But then, I can enter the admin page just by typing the url.

0

The exit part needs to be in the if statement:

if(!isset($_SESSION['username']))
{
  header("location:index.php");
  exit;
}

Having it outside of the if will prevent all content below it being displayed.

0

Strange, I cannot login if I have that code on. Like I have to comment out that code in order to login.

If you're curious the code that I have before that (my login code) - Login Code

0

I don't know if your login code on that thread is complete but I cannot see a session being started in there. You will need to put the session_start(); command at the top of that page too. Anything you put into a session variable on a page where no session has been started won't be set.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.