Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1543 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

php cookie question

Thread title: php cookie question
Closed Thread    
    Thread tools Search this thread Display Modes  
05-22-2006, 05:15 PM
#1
dan1088352 is offline dan1088352
Status: Member
Join date: Oct 2005
Location: Chicago, IL
Expertise:
Software:
 
Posts: 489
iTrader: 0 / 0%
 

dan1088352 is on a distinguished road

  Old  php cookie question

PHP Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
//get the post data
$post_username $_POST["username"];
$post_pass $_POST["pass"];

mysql_connect("-------","--------","--------");
mysql_select_db("-------");

$sql mysql_query("SELECT * FROM users WHERE username = '$post_username'") or die("$username doesnt exist in our records");

$passmysql_result($sql,'0',"password");
$username mysql_result($sql,'0',"username");
$id mysql_result($sql,'0',"id");

if(
$post_username == $username && $post_password == $password)
{
    echo 
"you are now logged in, please wait as I redirect you back to the index, click 
    <a href = \"index.php\">here if you arent directed</a>"
;
    
[
B]    setcookie("image_login","$id|$username|$pass");[/B]
}

else
{
    echo
" failed login, incorrect username or pass";
}
mysql_close();
?>
</body>
</html>
it gives me this error on the bolded line

Warning: Cannot modify header information - headers already sent by (output started at /home/theev2/public_html/forumresources/imagehost/login.php:8) in /home/theev2/public_html/forumresources/imagehost/login.php on line 27

what does that mean? ive done a million scripts with setcookie just like that

05-22-2006, 11:27 PM
#2
Dray is offline Dray
Dray's Avatar
Status: Request a custom title
Join date: Sep 2005
Location: Texas
Expertise:
Software:
 
Posts: 1,139
iTrader: 0 / 0%
 

Dray is on a distinguished road

  Old

The cookie needs to be set ABOVE everything else. What i mean is that the setcookie needs to go above:
PHP Code:
<html>
<
head>
<
title>Untitled Document</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>

<
body
and above any print() or echo().


For example:
PHP Code:
echo "you are now logged in, please wait as I redirect you back to the index, click 
    <a href = \"index.php\">here if you arent directed</a>"
;
    
    
setcookie("image_login","$id|$username|$pass");



 ; 
it still won't work because you have that echo above it.

05-23-2006, 03:59 AM
#3
dan1088352 is offline dan1088352
Status: Member
Join date: Oct 2005
Location: Chicago, IL
Expertise:
Software:
 
Posts: 489
iTrader: 0 / 0%
 

dan1088352 is on a distinguished road

  Old

ok, thanks

05-23-2006, 04:05 AM
#4
jono1 is offline jono1
jono1's Avatar
Status: Non-conformist
Join date: Jul 2005
Location: Canberra, Australia.
Expertise:
Software:
 
Posts: 1,172
iTrader: 0 / 0%
 

jono1 is on a distinguished road

  Old

Best to simply set the cookie and then execute a header("location: loggedinurl.php");, no real need to tell them that they've been logged in IMO, as long as they end up where they need to be.

05-23-2006, 04:18 AM
#5
dan1088352 is offline dan1088352
Status: Member
Join date: Oct 2005
Location: Chicago, IL
Expertise:
Software:
 
Posts: 489
iTrader: 0 / 0%
 

dan1088352 is on a distinguished road

  Old

I just put the echo after the setcookie

05-23-2006, 06:11 AM
#6
Dray is offline Dray
Dray's Avatar
Status: Request a custom title
Join date: Sep 2005
Location: Texas
Expertise:
Software:
 
Posts: 1,139
iTrader: 0 / 0%
 

Dray is on a distinguished road

  Old

Did it work?

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed