0

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.

4
Contributors
17
Replies
18
Views
5 Years
Discussion Span
Last Post by davy_yg
0

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>

Edited by urtrivedi: n/a

0

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.

0

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();

0

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

Edited by broj1: Added code snippet

0

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>
0

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.

0

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.

0

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().

0

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

0

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

Attachments
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Masterlink International</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="includes/navstyle.css" />
<script type="text/javascript" src="includes/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/superfish.js"></script>
<script type="text/javascript">
jQuery(function(){
	jQuery('ul.menu').superfish({
		animation: {opacity:'show',height:'show'},
		speed: 'slow', 
		autoArrows: true
	});
});
</script>
</head>



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

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


     

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


    </div>
    
<div id="menu">
            
 	<?php include ("includes/navigation.php"); ?>
        
</div>     

    
            
<div id="content">
      
      <?php 
	  
	  include('includes/koneksi.php');
	  
	  $result = mysql_query("SELECT * FROM static_page WHERE page = 'About'") or die (mysql_error()); 
	  
	  // ambil judul & isi berita kemudian print
	  $data = mysql_fetch_array($result);
	  		
	   echo '<h2>'.$data['judul'].'</h2><br><br>';
	   echo $data['isi_berita'];
			 
	  
	  
	  ?> 
		
      
</div>

      
     <?php include('includes/kategori_berita.php') ?>
      

  
    <?php include('banner.php') ?>

    
              
    <?php include('includes/event.php') ?>
      
        
    
    <?php include("includes/footer.php"); ?>
    
    
<p>&nbsp;</p>
</body>
</html>
0

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

Edited by broj1: n/a

0

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.

0

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();
}


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