Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Cant set cookie? w00t?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Exorcist
Posts: 35
Joined: 2006-05-24 07:48
Location: Oslo, Norway

Cant set cookie? w00t?

#1 Post by Exorcist »

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)

ajdlinux
Posts: 2452
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

#2 Post by ajdlinux »

Make sure there are no blank lines before the <?php tag.

Exorcist
Posts: 35
Joined: 2006-05-24 07:48
Location: Oslo, Norway

#3 Post by Exorcist »

EDIT 2: NVM, it works perfectly :D, thank you so much! :)
Ozzfest 06! :D (www.ozzfest.com)

Post Reply