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


?>

line 6: session_start();

The error appears after I enter my username and password.

Recommended Answers

All 5 Replies

Remove the unwanted empty lines in the top of the page. According to your code I am referring to line 1 and line 2

x

This error appears after I enter username and password.

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:29) in /home/sloki/user/masterli/sites/masterlink.co.id/www/cgoods/proseslogin.php on line 34


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://www.masterlink.co.id/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://www.masterlink.co.id/cgoods/admin.php");
	exit();
}


?>

Line 34: header("Location: http://www.masterlink.co.id/cgoods/admin.php");

Ahh right..
That happens because you have used an "echo" before the "header()". Remove the "echo"s

One more thing:

When I press Logout in admin page, it always appears first The webpage cannot be found. The link of the Logout.php is correct.

Logout.php

<?php
session_start();


// unset any session data 
session_unset();    
session_destroy();	
		
header("Location: http://www.masterlink.co.id/Masterlink/cgoods/index.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.