Jump to content

cookie problems


contra10

Recommended Posts

it worked it my localhost now i cant get it on the internet

 

my cookie does not set at all, i can acccess my other pages freely without a cookie if i type it in the url and when i enter the username and password from homepage i get this error

 

 

Warning: Cannot modify header information - headers already sent by (output started at /home/weew/public_html/index.php:16) in /home/weew/public_html/index.php on line 82

 

 

line 82 being

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

 

my code

 

<?php 
// Connects to your Database 
mysql_connect("localhost", "weew", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))

//if there is, it logs you in and directes you to the members page
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) 
{
if ($pass != $info['password']) 
{
}
else
{
header("Location: http://weew.com/main/");

}
}
}
$user = mysql_real_escape_string($_POST['username']);
$pas = mysql_real_escape_string($_POST['pass']);
//if the login form is submitted
if (isset($_POST['submit_x'])) { // if form has been submitted

// 4makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$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('That user does not exist in our database. <a href=registration.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check )) 
{
$verified= "{$info['verified']}";
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);

//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
//gives error if the password is wrong
if ($verified == 'no') {
die('you have not verified yet');
}
$HTTP_HOST = "http://weew.com/"; // our server's hostname

// if login is ok then we add a cookie 
$_POST['username'] = stripslashes($_POST['username']); 
$hour = time() + 3600; 
setcookie(ID_my_site, $_POST['username'], $hour, "", "weew.com"); 
setcookie(Key_my_site, $_POST['pass'], $hour, "", "weew.com");

header("Location: http://weew.com/main/"); 

} 
} 
else 
{ 

// if they are not logged in 
?> 

 

and the header file on all my pages

<?php
mysql_connect("localhost", "weew", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])) 
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
$in = mysql_query("SELECT username FROM users WHERE username ='$username'") or die (mysql_error());
$in2 = mysql_query("SELECT id FROM users WHERE username ='$username'") or die (mysql_error());
while($info = mysql_fetch_array( $check )) 
while($row = mysql_fetch_assoc($in))
while ($row2 = mysql_fetch_assoc($in2))
{ 

//if the cookie has the wrong password, they are taken to the login page 
if ($pass != $info['password']) 
{ 
ob_start();
   // Create the URL string
   $url = "http://weew.com/"; 
   
   // Finall Echo the meta tag
   echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">');
} 
//otherwise they are shown the admin area 
else{
$user = "{$row2['id']}";
$userq = "{$row['username']}";

} 
}
}
else

//if the cookie does not exist, they are taken to the login screen 
{ 


} 
mysql_close();
?>

 

 

Link to comment
Share on other sites

have a look at the output page with the error

output is happening on line 16

now looking at your code i think line 16 is

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

now that makes no output unless $pass or $info['password'] is not set and it looks like both are set.

really the only advice i can offer is check your output to see if there is anything else.

 

Scott.

Link to comment
Share on other sites

 

<head>
<title>title</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="body2">
<div id="body3">
<div id="container">
  <div id="header">
    <div id="headerleft">
      <div id="title"><img src="eventwireimg.png"></div>
    </div>
    <div id="headerright">
      <div id="flickr"></div>
      <div id="search">
<?php 
// Connects to your Database 
mysql_connect("localhost", "weew", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
?>

 

line 16 is to be exact "<?php"

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.