Jump to content

Cannot modify header information - headers already sent by (...).....


UnknownPlayer

Recommended Posts

Why do i get this error when i put code for redirection on my php code :S

Warning: Cannot modify header information - headers already sent by (output started at /home/dotars/public_html/shop/includes/functions.php:3) in /home/dotars/public_html/shop/includes/functions.php on line 20

 

This is that code on functions.php on line 20:

function confirm_logged_in() {
	if (!logged_in()) {
		redirect_to("login.php");
	}
}
function redirect_to($location = NULL) {
	if ($location != NULL) {
		header("Location: {$location}");
		exit;
	}
}

 

And this is the code in the other php code:

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>

<!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>Untitled Document</title>
</head>

<body>
<center>
Text...
</center>
</body>
</html>

 

And confirm_logged_in() function is:

 

Link to comment
Share on other sites

A "pro" php tip is to always omit the ending php tag from any script that only includes PHP code.  A line or 2 of whitespace can inadvertantly cause output to be triggered in scripts where you never intended that to happen -- like your functions.php include script.  Whenever a script is included, you have to realize that it is injected as is, into the including script.  Since PHP allows for the intermixing of PHP and HTML.  Leaving off the end tag will eliminate that problem.

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.