Cant set cookie? w00t?

Need help with C, C++, perl, python, etc?

Cant set cookie? w00t?

Postby Exorcist » 2006-05-26 09:37

Hello all :)
Im working on an admin script in php for a cms:
Code: Select all
<?php
 include 'dbconnect.php';

 if ($_POST['login'] || $_COOKIE['kjelsaas.admin'] == 'DWASDA23FASDW') {
   $userq = mysql_query("SELECT user, password FROM admin;");
   while ($user = mysql_fetch_array($userq)) {
     if ($_POST['uname'] == $user[0] && $_POST['passwd'] == $user[1]) {
       setcookie("kjelsaas.admin", 'DWASDA23FASDW', time()+3600);
       $i = 0;
       $linksq = mysql_query("SELECT page, adress FROM admin_panel ORDER BY id ASC;");
       while ($links = mysql_fetch_array($linksq)) {
         if ($i >= 1) { echo " | "; }
         echo "<a href='http://www.kjelsaas.no/test/$links[1]'>$links[0]</a>";
    echo $_COOKIE['kjelsaas.admin']; //debuging
    $i++;
       }
     }
     else echo "Get lost";
   }
 }
 else {
   include 'admin.htm';
 }

When i log on, everything except the cookies work, so i get an error telling me:
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /var/www/00/14/15/kjelsaas.no/www/test/admin.php:1) in /var/www/00/14/15/kjelsaas.no/www/test/admin.php on line 8


BUT, if i set the cookie like this:
Code: Select all
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value, time()+3600);
echo $_COOKIE['TestCookie']; // debuging
?>
i dont get an error at all, and the cookie displays as its ment to.

Why doesnt it work?!? :(

EDIT: The admin.htm is just a post form (to show the password and username things).
Ozzfest 06! :D (www.ozzfest.com)
Exorcist
 
Posts: 35
Joined: 2006-05-24 07:48
Location: Oslo, Norway

Postby ajdlinux » 2006-05-26 10:20

Make sure there are no blank lines before the <?php tag.
ajdlinux
 
Posts: 2480
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

Postby Exorcist » 2006-05-26 10:25

EDIT 2: NVM, it works perfectly :D, thank you so much! :)
Ozzfest 06! :D (www.ozzfest.com)
Exorcist
 
Posts: 35
Joined: 2006-05-24 07:48
Location: Oslo, Norway


Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable