[PHP] Cannot modify header information

Status
Niet open voor verdere reacties.

gebruiker241

Gebruiker
Lid geworden
8 mrt 2008
Berichten
209
Hallo!
Ik maak een ledensysteem, en nu kreeg ik een error :'(
De error:
Warning: Cannot modify header information - headers already sent by (output started at D:\Websites\xampp\xampp\htdocs\MAPP met lay\Mapp\website.php:57) in D:\Websites\xampp\xampp\htdocs\MAPP met lay\Mapp\functies\hoofd.functie.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at D:\Websites\xampp\xampp\htdocs\MAPP met lay\Mapp\website.php:57) in D:\Websites\xampp\xampp\htdocs\MAPP met lay\Mapp\functies\hoofd.functie.php on line 5

Mijn bestanden:

Functies\hoofd.functie.php (regel 1t/m 7):
Code:
<?php
function inloggen($gebruikersnaam,$wachtwoord) {
				
	setcookie("gebruikersnaam", $gebruikersnaam, time() + 60*60);
	setcookie("wachtwoord", $wachtwoord, time() + 60*60);
	$_SESSION['gebruikersnaam'] = $gebruikersnaam;
}

Website.php (Regel 57 t/m Regel 59:
Code:
			<?php
			include ('menu.php');
			?>


Menu.php (Alle regels):
Code:
<?php
if(!isset($_SESSION['gebruikersnaam'])){
echo "<a href='?p=home'>&gt; Home</a><br/>";
echo "<a href='?p=login'>&gt; Login</a><br/>";
echo "<a href='?p=registreren'>&gt; Registeren</a><br/>";
}else{
echo "<a href='?p=home'>&gt; Home</a><br/>";
echo "<a href='?p=beveilig'>&gt; Beveligde pagina</a><br/>";
echo "<a href='?p=profiel&mid=$memb_id'>&gt; Mijn Profiel</a><br/>";
echo "<a href='?p=veranderwachtwoord'>&gt; Wachtwoord veranderen</a><br/>";
echo "<a href='?p=loguit'>&gt; Uitloggen</a><br/>";
}
?>

Ik weet niet hoe ik dit moet oplossen.
Weet iemand dit wel? Zoja, hoe?
Alvast bedankt!
 
Er wordt output naar de browser verstuurd voordat jij nog een header probeert te wijzigen. In dit geval (naar alle waarschijnlijkheid bij setcookie). Dat wil zeggen, dat je misschien een spatie, een enter of wat dan ook stuurt, wat je niet eens noodzakelijk kunt zien, maar er wel is.

De oplossing?

Simpelweg zorgen dat het setten van de cookie het allereerste is wat op je pagina gebeurt voor je output verstuurt.

Op Website.php verstuur je al een aantal tabs/spaties, dus dan kun je al geen cookie meer setten. Ik zie echter in je code niet waar hoofd.functie.php geinclude wordt... Misschien kun je even de volledige code posten?
 
in menu.php staat daar soms een regel met de header-functie.
Zou je anders de hele file en van menu.php kunnen posten!
 
Mijn volledige website.php:

Code:
<?php
session_start();
include ('functies/hoofd.functie.php');

include ('config.php');

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

<head>
<title>JustHabbo.org ~ Meer dan een alleen een fansite!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/opmaak.css" />
</head>


<body>
	<div id="content">
		<div id="top_star">	</div>
			<div id="orangje_balk"><img border="0" src="images/buttons/home.png" width="97" height="34"><img border="0" src="images/buttons/nieuws.png" width="97" height="34"><img border="0" src="images/buttons/events.png" width="97" height="34"><img border="0" src="images/buttons/informatie.png" width="97" height="34"><img border="0" src="images/buttons/leden.png" width="97" height="34"><img border="0" src="images/buttons/contact.png" width="99" height="34"></div>
		<div id="top_header">
		<div id="header"></div>
		<div id="short">
			<div id="buttons">	<img border="0" src="images/buttons/blogs.png" width="94" height="22"><img border="0" src="images/buttons/reacties.png" width="95" height="22"><img border="0" src="images/buttons/leden_2.png" width="97" height="22">	</div>
			<div class="line_1"><a href=" ">	- Wat een dag weer vandaag!</a>	</div>
			<div class="line_2"><a href=" ">	- Eindelijk me de cito zit erop!</a>	</div>
			<div class="line_3"><a href=" ">	- Heb een nieuwe badges binnen.</a>	</div>
			<div class="line_4"><a href=" ">	- Hoi, ik ben GoldSpray</a>	</div>
		</div>
	</div>
		<div id="bruin_balk">
			<div class="datum">
			Zaterdag, 2 April 2011&nbsp;- <script language="JavaScript">
			<!--
			function d(T){
			document.write(T);
			}
			var Datum = new Date();

			d(Datum.getHours()+(Datum.getTimezoneOffset()/60));d(':');d(Datum.getMinutes());

			//-->
			</script>
			</div>
		</div>
		<div id="mid"></div>
	
	<div id="midden">
<div id="pagina">
<table>
<tr>
<td valign="top">
<div id="box_left">
    			<div id="login"><img border="0" src="images/login/registreren.png" width="120" height="22"><img border="0" src="images/login/login.png" width="121" height="22"></div>
    		
    			<div id="small_box_top">Navigator</div>
			<div id="small_box_mid"><?php include ("menu.php"); ?>
			<div style="clear: both;"></div>
			</div>
			<div id="small_box_bot">				</div>
</div>
</td>
<td valign="top">

			    <div id="content_small_top">Welkom op JustHabbo</div>
	<div id="content_small_mid">


    			
			<?php



// Einde hyves respect button
$page=$_GET['p'];
if($page)
{
if(file_exists('pagina/'.$_GET['p'].'.php'))
{
  include('pagina/'.$_GET['p'].'.php');
}
else
{
  include("pagina/404.php"); // de url van je 404 pagina
}
}
else
{
  include("pagina/home.php"); // de pagina die als index weergegeven moet worden
} 
?>


			<div style="clear:  both;"></div>
</div>
	<div id="content_small_bot"></div>
    			

</td>
<td valign="top">
<div id="box_right">
    			<div id="small_box_top">Statistieken</div>
			<div id="small_box_mid">
			Er zijn nu 0 bezoekers online en daar van zijn er 0 leden online. Daar naast zijn er 0 artikelen geschreven en daarop is al 0 keer gereageerd.
			</div>
			<div id="small_box_bot">				</div>

			<div id="small_box_top_bruin">Laatste Badges</div>
			<div id="small_box_mid"></div>
			<div id="small_box_bot">				</div>

			<div id="small_box_top_bruin">Agenda</div>
			<div id="small_box_mid"></div>
			<div id="small_box_bot">				</div>

			<div id="small_box_top_bruin">Random partner</div>
			<div id="small_box_mid">
			<p align="center"><a target="_blank" href="http://justhabbo.org/"><img border="0" src="images/banner.png"></a></p>		
			<center><a href="http://justhabbo.org/">Bezoek JustHabbo.org</a></center>
			</div>
			<div id="small_box_bot">				</div>
</div>
</td>
</tr>
</table>
</div>
	</div>
	<div id="bruin_balk">
			<div class="copyright">© JustHabbo.org</div>
	</div>


</div> 
</body>




</html>
Mijn funcites/hoofd.functie.php
Code:
<?php
function inloggen($gebruikersnaam,$wachtwoord) {		
	setcookie("gebruikersnaam", $gebruikersnaam, time() + 60*60); // cookie blijft 60 keer 60 seconden bestaan
	setcookie("wachtwoord", $wachtwoord, time() + 60*60);
	$_SESSION['gebruikersnaam'] = $gebruikersnaam;
}






// Calculate the age from a given birth date
// Example: GetAge("1986-06-18");
function GetAge($Birthdate)
{
        // Explode the date into meaningful variables
        list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $Birthdate);
        // Find the differences
        $YearDiff = date("Y") - $BirthYear;
        $MonthDiff = date("m") - $BirthMonth;
        $DayDiff = date("d") - $BirthDay;
        // If the birthday has not occured this year
        if ($DayDiff < 0 || $MonthDiff < 0)
          $YearDiff--;
        return $YearDiff;
}



// Retrieve age & days till next birthday 
// Version 0.1.2, based on examples which could be found at http://www.php.net/date 
// Written by Steven Goos 

// count number of leap years between birthday and today 
function numOfLeapDays($from, $to) { 
    if((checkdate(2,29,date("Y",$from))) && ($from > mktime(0,0,0,2,29,date("Y",$from)))) { 
        $fromYear = date("Y",$from)+1; 
    } else { 
        $fromYear = date("Y",$from); 
    } 

    if((checkdate(2,29,date("Y",$to))) && ($to < mktime(0,0,0,2,29,date("Y",$to)))) { 
        $toYear = date("Y",$to)-1; 
    } else { 
        $toYear = date("Y",$to); 
    } 

    $numOfLeapDays = 0; 

    for($i = $fromYear; $i <= $toYear; $i++) { 
        if ((($i % 4) == 0) AND ((($i % 400) == 0) OR (($i % 100) <> 0))) $numOfLeapDays++; 
    } 
    return $numOfLeapDays; 
} 


// retrieve age and number of days till next birthday 
function agenext($birthday){ 
    // format dd-mm-yyyy -> [0] = day, [1] = month, [2] = year 
    $datekey = explode("-",$birthday); 

    // basic variables 
    $born = mktime(0,0,0,$datekey[1],$datekey[0],$datekey[2]); 
    $now = mktime(0,0,0,date("m"),date("d"),date("Y")); 
    $nextbirthday = mktime(0,0,0,$datekey[1],$datekey[0],date("Y")); 
    if($nextbirthday < $now) { 
        $nextbirthday = $nextbirthday + (60*60*24*365); 
    } 

    // days till next birthday 
    $days = intval(($nextbirthday - $now) / (60*60*24)); 

    $agenext = "".$days." dag".($days == 1 ? "":"en").""; 
    return $agenext; 
} 

// call function with: agenext($birthday) 


?>

Alvast bedankt!
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan