hey people .
i am trying to set a cookie but when ever i try to set it, it says :

Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\signup\conf.co.signup.php on line 13

please help me with this.
this is my code:

<?php
error_reporting(-1);
if(isset($_COOKIE['logedin']))
{
?>
<script type="text/javascript">window.location ="../home.php";</script>
<?php 
}
else
{
$id = $_GET['id'];
$time = date()+60*60*24*30;
$q = setcookie("logedin", $id, $time);
if($q){
?>
<script type="text/javascript">
window.location = "../home.php";
</script>
<?php 
}
else
{
?>
<div id="dialog" title="Error"><p>cant create the cookie</p></div>
<?php
}
//the last closing }
}

thanks

cookies need to be send before any other output

check for white space Before <?php tag

also could try

if(isset($_COOKIE['logedin']))
   {
   header("Location: http://www.example.com/");
   }
else

cant test myself now so no guarantees

thanks but that is not working.
i removed tried to use sessions but it is still cant work
check this is my new code:

<?php
session_start();
error_reporting(-1);
/*if(isset($_COOKIE['logedin']))
{
header("location: ../home.php");
}
else
{*/
$time = 60*60*60*24*30; 
$id = (int) $_GET['id'];
$q = setcookie("logedin", $id, $time);
if($q)
{
?>
<script type="text/javascript">window.location = "../home.php";</script>
<?php
}
//the last closing }
//}

this perfectly works but when i check for the cookie in the home.php it says there is not cookie.
here is the home.php code

<?php
error_reporting(-1);
if(!isset($_COOKIE['logedin']))
{ ?>
<html>
<head><title>Please Login</title>
<?php 
include "engine/includes/ui.php";
?>
<script type="text/javascript">
			$(function(){
				// Dialog			
				$('#dialog').dialog({
					autoOpen: true,
					width: 600,
					height: 300,
					
					buttons: {
						"Continue": function() { 
							$(this).dialog("close"); 
							window.location = "index.php";
						}, 
						
					}
				});
				
			});
</script>
</head>
<body>
<div id="dialog" title="Please Login">
<p>
You Are not loggged in!
</p>
</div>
</body>
</html>
<?php }else{ ?>
<html><head>
<title>Home | AZONE</title>
<link rel="stylesheet" href="logedin.css" media="all" type="text/css" />
<?php 
include "engine/includes/ui.php";
?>
<script type="text/javascript">
			$(function(){
				// Dialog			
				$('#dialog').dialog({
					autoOpen: true,
					width: 600,
					height: 300,
					
					buttons: {
						"Continue": function() { 
							$(this).dialog("close"); 
							window.location = "index.php";
						}, 
						
					}
				});
				
			});
</script>
</head>
<body>

</body>
</html>
<?php
// the last } shouldn't be removed
}

what can i do now??
and when i came to signup it says the cookie is already set.
and when i come to signin it signs me in but it still the home page have error

here is the signin page:

<?php
error_reporting(-1);
if(isset($_COOKIE['logedin']))
{
?>
<script type="text/javascript">window.location = "../home.php";</script>
<?php 
}
else
{
if(!isset($_POST['email']))
{
?>
<script type="text/javascript">window.location="index.php";</script>
<?php 
}
else
{?>

<?php 
//here the login code
$email = $_POST['email'];
$password = $_POST['password'];
$password = md5($password);
include_once "../engine/db/main.php";
$db = new db();
$db->connect();
$db->select("awah7870_users");
$email = mysql_real_escape_string($email);
?><html>
<head>
<title>Login Check</title>
<style>
	.ui-progressbar-value { background-image: url(../graphics/pbar-ani.gif); }
	</style>
<?php include "../engine/includes/ui.php"; ?>
     <script type="text/javascript">
			$(function(){

				

				// Dialog			
				$('#dialog').dialog({
					autoOpen: true,
					width: 600,
					height: 300,
					
					buttons: {
						"Continue": function() { 
							$(this).dialog("close"); 
							window.location = "index.php";
						}, 
						
					}
				});
				
			});
		</script>
    
	
    </head>
    <body>
   
<?php 
$q = mysql_query("SELECT * FROM `all` WHERE email = '$email' AND password = '$password'");
if(!$q)
{
?>
<!-- ui-dialog -->
		<div id="dialog" title="An Error Has Occured">
			<p>Sorry, an Error has occured while we are trying to log you in. The Adiministrations System is being notified with this error and we are already trying to fix the error. Please Try again Laiter<BR /><BR /><B><?php echo mysql_error();
			$message =  "ERROR HAS OCCURED WHILE THE USER \" ".$email." \" was trying to login with the password \" ".$password." \" in the following link: http://awah.biz/login/login.php witht the ollowing error:".mysql_error()." ";
			$title = "Login Error";
			$headers = "FROM: the AZONE NOTIICATION SYSTEM";
			mail("errors@awah.biz", $title, $message, $headers);
			 ?></B></p>
		</div>
<?php 
}
else
{
if(mysql_num_rows($q) == 0)
{
?>
<div id="dialog" title="Oops">
<p>
Sorry, we couldnt found your Email or Password in our databases. please try again
</p>
</div>
<?php 
}
else if(mysql_num_rows($q) >= 1)
{
while($row = mysql_fetch_array($q))
{
$id = $row['id'];
}
$time = date()+60*60*24*30;
setcookie("logedin", $id, $time);
?>
<script type="text/javascript">window.location = "../home.php"; </script>
<?php 

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