index.php

<body>
    <?php include("includes/header.php"); ?>

<?php     

//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>

<div id="login">
      
      <form action="proseslogin.php" method="post" name="login" target="_self" id="login" style="style.css" title="login"><br />
          <label>user    :          </label>
          <input type="text" name="username" id="username" />
          <label>password:          </label>
          <input type="text" name="password" id="password" />
          <input type="submit" name="Login" id="Login" value="Login" />
       </form>	
		
        
<div id="searchwrapper"><form action="search.php">
<input type="text" class="searchbox" name="s" value="Search" onFocus="if (this.value=='Search')this.value='';" onBlur="if (this.value=='')this.value='Search'" />
<input type="image" src="Images/submit2.jpg" class="searchbox_submit" value="" />
</form></div>


    </div>

There are some errors in my web.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php:8) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php on line 29

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php:8) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php on line 29


line 29 is line 8 in my codes above.

Start with php tag. Do not keep any space, newline or any Character in the beginning. Here <body> and newline creating problem.

<?php     
//start session    
session_start();     
include("includes/header.php");
//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>
<body>
<div id="login">
      
      <form action="proseslogin.php" method="post" name="login" target="_self" id="login" style="style.css" title="login"><br />
          <label>user    :          </label>
          <input type="text" name="username" id="username" />
          <label>password:          </label>
          <input type="text" name="password" id="password" />
          <input type="submit" name="Login" id="Login" value="Login" />
       </form>	
		
        
<div id="searchwrapper"><form action="search.php">
<input type="text" class="searchbox" name="s" value="Search" onFocus="if (this.value=='Search')this.value='';" onBlur="if (this.value=='')this.value='Search'" />
<input type="image" src="Images/submit2.jpg" class="searchbox_submit" value="" />
</form></div>


    </div>

You send some html (<body>...) before session_start() which is not allowed (unless you buffer of output or do not use cookie based session). Move session functions to the beginning of the script.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php:8) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php on line 25

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php:8) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/index.php on line 25

index.php

<?php include("includes/header.php"); ?>     

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>

<body>
<div id="login">
      
      <form action="proseslogin.php" method="post" name="login" target="_self" id="login" style="style.css" title="login"><br />
          <label>user    :          </label>
          <input type="text" name="username" id="username" />
          <label>password:          </label>
          <input type="text" name="password" id="password" />
          <input type="submit" name="Login" id="Login" value="Login" />
       </form>	
		
        
<div id="searchwrapper"><form action="search.php">
<input type="text" class="searchbox" name="s" value="Search" onFocus="if (this.value=='Search')this.value='';" onBlur="if (this.value=='')this.value='Search'" />
<input type="image" src="Images/submit2.jpg" class="searchbox_submit" value="" />
</form></div>

Similar error still appears. line 25 is: session_start();

It looks to me like you are already calling session_start() somewhere - maybe in your header.php file.

Is there any content sent in your included header.php file? Why don't you move session_start() to the very beginning (line 1)?

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 

include("includes/header.php");
?>

it still does not work.

my whole code of:

header.php

<head>
<link href="../style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="./headerscript.css" />
<script type="text/javascript" src="script.js"></script>

<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>

<div id="header"><img src="./Images/Masterlink Banner.jpg" height="200" width="983" align="left"/></div>

</head>
<body>
<div id="wrapper">
	<div class="sliderbutton" id="slideleft" onClick="slideshow.move(-1)"></div>
		<div id="slider">
			<ul>
				<li><img src="./Images/1.jpg" width="558" height="200" alt="Image One" /></li>
				<li><img src="./Images/2.jpg" width="558" height="200" alt="Image Two" /></li>
				<li><img src="./Images/3.jpg" width="558" height="200" alt="Image Three" /></li>
				<li><img src="./Images/4.jpg" width="558" height="200" alt="Image Four" /></li>
			</ul>
		</div>
		<div class="sliderbutton" id="slideright" onClick="slideshow.move(1)"></div>
		<ul id="pagination" class="pagination">
			<li onClick="slideshow.pos(0)"></li>
			<li onClick="slideshow.pos(1)"></li>
			<li onClick="slideshow.pos(2)"></li>
			<li onClick="slideshow.pos(3)"></li>
		</ul>
	
</div>
<script type="text/javascript">
var slideshow=new TINY.slider.slide('slideshow',{
	id:'slider',
	auto:4,
	resume:false,
	vertical:false,
	navid:'pagination',
	activeclass:'current',
	position:0,
	rewind:false,
	elastic:true,
	left:'slideleft',
	right:'slideright'
});
</script>
</body>

Well your header.php is wrong - you are opening and closing the body tags in the header file and then again in your main page. Your header file should only be the code that is within the header of your page. Plus you are not declaring <html> in the header. I suggest creating your page as a whole first, testing it and then once working take out everything that you want to be in your header.php file and move it into that file.

only my other page that does not have the following code works well:

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>

I already try to add <html> and delete <body> the same still remains.

Have you tried what I suggested (all in one page) - I am unsure from your reply?

If the error is the same as in your first post you still output some content before calling session_start(). Make sure there is nothing sent (even not a space before a ?php tag) before the call to session_start().

I just did. still the same error appears, in session_start();

Please show the full and exact code in one page so we can look again at what you have now based on my suggestion.

I attached the file. (it's 156 lines).

You output a lot of html before calling a session_start() which is not OK. Put the call to session_start() at the very beginning of the file not on the line 78 as it is now.

<?php
//start session    
session_start();     

//unset any session data until user submits valid username and password    
// this is correct way not unset($_SESSION), sorry my mistake    
// see http://www.php.net/manual/en/function.session-unset.php    

session_unset();    
session_destroy(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...

Other errors:
- the <body> tag should immediately follow the </head> tag
- you have two <head></head> blocks in your file

I give up - we have already told the poster all of this - put the session_start() at the top of the page, format the page properly etc and none of it is being done by the looks of it.

Now, it works! thanks.

Well, I find a new error. After my session location I am having error in proseslogin.php

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/proseslogin.php:3) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/proseslogin.php on line 6

Di sini blok aplikasi setelah login dilakukan
Anda berhasil menjalankan!
Warning: Cannot modify header information - headers already sent by (output started at /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/proseslogin.php:3) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/proseslogin.php on line 36

proseslogin.php

<?php

// start session
session_start(); 

$username = $_POST['username'];
$password = $_POST['password'];
$login = isset($_POST['login']) ? $_POST['login'] : false;

//function
function periksa ($username, $password){
		if (($username=="****") and ($password=="******")){
			return true;
		}else{
			return false;
		}
	}	
	
// cek		
if (periksa($username, $password)) {
		$login=true;	
}
else {
		echo "User ID atau password salah!";
		
		header("Location: http://localhost/Masterlink/cgoods/index.php");
}
if ($login) {
	echo "<br>Di sini blok aplikasi setelah login dilakukan";
	echo "<br>Anda berhasil menjalankan!";
	
	// buat session username
	$_SESSION['username'] = $username;	
	header("Location: http://localhost/Masterlink/cgoods/admin.php");
	exit();
}


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.