Jump to content

cannot modify header information >< need help. - cookies


Minimeallolla

Recommended Posts

<body background="homebackground.jpg">

<style type="text/css">

<!--

A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal }

A:visited { COLOR: black; TEXT-DECORATION: none; font-weight: normal }

A:active { COLOR: green; TEXT-DECORATION: none }

A:hover { COLOR: blue; TEXT-DECORATION: none; font-weight: none }

-->

</style>

<?php

 

 

 

include ("database.php");

 

//Checks if there is a login cookie

if(isset($_COOKIE['ID_my_site']))

{

$username = mysql_real_escape_string( $_COOKIE['ID_my_site'] );

$pass = mysql_real_escape_string( $_COOKIE['Key_my_site'] );

 

$check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error());

 

while($info = mysql_fetch_array( $check ))

{

if ($pass == $info['password'])

  print("<meta http-equiv='Refresh' content='0;index.php' />");

 

}

}

 

//if the login form is submitted

if (isset($_POST['submit']))

{ // if form has been submitted

 

// makes sure they filled it in

if(!$_POST['username'] | !$_POST['pass'])

die('

<body background="homebackground.jpg"><center><p><br><p><b>

You did not fill in a required field, <a href="login.php"><b>

click here to try again.</a></center></b></b>

');

 

// checks it against the database

if (!get_magic_quotes_gpc())

$_POST['email'] = addslashes($_POST['email']);

$_POST['username'] = stripslashes($_POST['username']);

 

$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

 

//Gives error if user dosen't exist

$check2 = mysql_num_rows($check);

 

if ($check2 == 0)

die('

<body background="homebackground.jpg"><center><p><br><p><b>

That user does not exist in our database, <a href=add.php><b>

click here to Register</a></b></b></center>

');

 

while($info = mysql_fetch_array( $check ))

{

$_POST['pass'] = stripslashes($_POST['pass']);

$_POST['pass'] = md5($_POST['pass']);

 

//gives error if the password is wrong

if ($_POST['pass'] != $info['password'])

die('

<body background="homebackground.jpg"><center><p><br><p><b>

Invalid password, <a href="login.php"><b>click here to try again.</b></b></a>

');

else

{

// if login is ok then we add a cookie

$_POST['username'] = stripslashes($_POST['username']);

$_POST['password'] = stripslashes($_POST['password']);

$hour = time() + 3600;

setcookie("ID_my_site", $_POST['username'], $hour);

setcookie("Key_my_site", $_POST['pass'], $hour);

 

//then redirect them to the members area

if ($pass == $info['password'])

print "you have logged in.";

print("<meta http-equiv='Refresh' content='0;index.php' />");

}

}

}

else

{

 

// if they are not logged in

 

?>

<?php

include ("nav.php");

?>

 

<center>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<table border="0">

<tr><td colspan=2><h1> Log in</h1></td></tr>

<tr><td>Username:</td><td>

<input type="text" name="username" maxlength="40">

</td></tr>

<tr><td>Password:</td><td>

<input type="password" name="pass" maxlength="50">

</td></tr>

<tr><td colspan="2" align="right">

<input type="submit" name="submit" value="Login">

</td></tr>

</table>

</form>

  </center>

<?php

}

?>

  <HTML>

<HEAD>

<link rel="favicon.ico" href="***/favicon.ico">

<title>

My site

</title>

</HEAD>

<BODY>

If you read the error message you are getting, it tells you where you are sending the output at that is preventing the setcookie/header from working.

 

You cannot send any CHARACTERS * to the browser prior to a header.

 

* Characters are anything that is not a header.

 

ALL of your HTML tags and css are CHARACTERS.

 

 

SOLVED:

 

Characters are only sent in If and Else statements?

 

Warning: Cannot modify header information - headers already sent by (output started at **/login.php:2) in /**/login.php on line 78

 

Warning: Cannot modify header information - headers already sent by (output started at **/login.php:2) in /**/login.php on line 79

 

There are no other headers prior to the setcookie script?

 

 

background and css moved = solved :D

 

SOLVED: with help from "PFMaBiSmAd", Thank you, much appreciated.

"* Characters are anything that is not a header.

 

ALL of your HTML tags and css are CHARACTERS."

- PFMaBiSmAd

 

<body background="homebackground.jpg">
<style type="text/css">
<!--
A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal }
A:visited { COLOR: black; TEXT-DECORATION: none; font-weight: normal }
A:active { COLOR: green; TEXT-DECORATION: none }
A:hover { COLOR: blue; TEXT-DECORATION: none; font-weight: none }
-->
</style>
<?php 



include ("database.php"); 

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
{
	$username = mysql_real_escape_string( $_COOKIE['ID_my_site'] ); 
	$pass = mysql_real_escape_string( $_COOKIE['Key_my_site'] );

	$check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error());

	while($info = mysql_fetch_array( $check )) 	
	{
		if ($pass == $info['password']) 
		  print("<meta http-equiv='Refresh' content='0;index.php' />");

	}
}

//if the login form is submitted 
if (isset($_POST['submit']))
{ // if form has been submitted

	// makes sure they filled it in
	if(!$_POST['username'] | !$_POST['pass'])
		die('
		<body background="homebackground.jpg"><center><p><br><p><b>
		You did not fill in a required field, <a href="login.php"><b>
		click here to try again.</a></center></b></b>
		');

	// checks it against the database
	 if (!get_magic_quotes_gpc())
		$_POST['email'] = addslashes($_POST['email']);
		$_POST['username'] = stripslashes($_POST['username']);

	$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

	//Gives error if user dosen't exist
	$check2 = mysql_num_rows($check);

	if ($check2 == 0)
		die('
		<body background="homebackground.jpg"><center><p><br><p><b>
		That user does not exist in our database, <a href=add.php><b>
		click here to Register</a></b></b></center>
		');

	while($info = mysql_fetch_array( $check )) 	
	{
		$_POST['pass'] = stripslashes($_POST['pass']);
		$_POST['pass'] = md5($_POST['pass']);

		//gives error if the password is wrong
		if ($_POST['pass'] != $info['password'])
			die('
			<body background="homebackground.jpg"><center><p><br><p><b>
			Invalid password, <a href="login.php"><b>click here to try again.</b></b></a>
			');
		else 
		{ 
			// if login is ok then we add a cookie 
			$_POST['username'] = stripslashes($_POST['username']); 
			$_POST['password'] = stripslashes($_POST['password']); 
			$hour = time() + 3600; 
 			setcookie("ID_my_site", $_POST['username'], $hour); 
			setcookie("Key_my_site", $_POST['pass'], $hour);	 

			//then redirect them to the members area 
			if ($pass == $info['password'])
		print "you have logged in.";
		print("<meta http-equiv='Refresh' content='0;index.php' />");
		} 
	} 
} 
else 
{	 

 // if they are not logged in 

?> 
<?php
include ("nav.php");
?>

<center>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
<table border="0"> 
<tr><td colspan=2><h1>		Log in</h1></td></tr> 
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr> 
</table> 
</form> 
  </center>
<?php 
}
?> 
   <HTML>
<HEAD>
<link rel="favicon.ico" href="***/favicon.ico">
<title>
My site
</title>
</HEAD>
<BODY>
[/quote]
[code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.