Page 1 of 1

Cookie Setting Prob

Posted: Sun Jun 19, 2005 7:16 am
by Ruski
Im making a simple login form and everything works perfect exept for setting the cookie, it shows this error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/rsneebn/public_html/connect.php:9) in /home/rsneebn/public_html/logins.php on line 64

Code: Select all

line 64: setcookie("rscheetah_cookie", serialize(array($user, $pass)), time() + 31536000, '/', '', 0);
I never seen an error like that before.

Thanks in advance

Posted: Sun Jun 19, 2005 8:10 am
by Chris Corbyn
You've got output somewhere above that (content sent back to the browser)...

The cookie is set within the headers and if they have already been sent you get errors.

It might just be a chunk of whitespace or something....

Search these forums for "Headers already sent" and you'll get a tonne of posts.

Posted: Sun Jun 19, 2005 8:34 am
by Ruski
is setcookie funtion a header call?
as i checked my connect.php and the script where setcookie is called, i dont have any white space or outputs. Here is my connect.php:

Code: Select all

<?php 
include 'mysql.php'; 
$db = new DBLayer('localhost', 'user', 'pass', 'database', '', false);
?>
here is my script that sets the cookie:

Code: Select all

<?
include 'methods.php';
$do = $_GET['act'];
$user = trim($_POST['username']);
$pass = trim($_POST['password']);
if($do == 'verify')
{
	if($user == '' || $pass == '')
	{
		alert('Please type both username and password to login!');
		redirect('http://www.rscheetah.com/logins.php');
	}	
	$find = $db->query('SELECT * FROM users WHERE username=\''.$user.'\'');
	$finder = $db->fetch_assoc($find);
	if($finder['password'] != $pass)
	{	
		alert('Wrong username or password!');	
		redirect('http://www.rscheetah.com/logins.php');
	}
	else
	{		
	          	setcookie("rscheetah_cookie", serialize(array($user, $pass)), time() + 31536000, '/', '', 0);					 
			alert('Logged on successfully');
			redirect('http://www.rscheetah.com/logins.php');	
	} 
}
elseif($do == 'panel')
{
	echo '<label class="main">Cant find act specified</label>';
}
?>
Thanks for your help though