okay, i read over the php manual on setcookie. so to make the cookie never expire, would it look like this?

$COOKIE['username', int expire(0)];
$
COOKIE['passwd', int expire(0)];

i feel dumb, cause i'm pretty sure thats wrong.

    First, you have to use setcookie() to set a cookie...

    Second, if you set the expiration time to 0, the cookie will be ereased when the browser is closed.

    Third, you could put a date which is very far from now...

    setcookie("TestCookie" ,$value, mktime (0, 0, 0, 12, 31, 2015));

    This would expire December 31th 2015 !

      thanks 😃 so would it look like this?

      $_COOKIE("username" ,$value, mktime (0, 0, 0, 12, 31, 2015));

      whats the $value for?

        No...

        Not :
        $_COOKIE("username" ,$value, mktime (0, 0, 0, 12, 31, 2015));

        But :
        setcookie("TestCookie" ,$value, mktime (0, 0, 0, 12, 31, 2015));

        Where TestCookie is the name of the cookie, and $value is... the value of the cookie...

          how come i have to use the setcookie() ? just wondering.

            Ok...

            First... $COOKIE() is bad... you must use $COOKIE[]...

            Second... $_COOKIE["the_name_of_the_cookie"] will return the value of the cookie. If you modify it in PHP, the value will not be changed on the client-side...

            Third, you must use setcookie() because a cookie is in fact a header which is sent to the user. You could write it yourself, but you have a function that exists just for that, so use it !

            Also, if you use :
            $_COOKIE("username" ,$value, mktime (0, 0, 0, 12, 31, 2015));

            You'll get an error...

            Suppose you have this :

            $var1 = "strtolower";
            $var2 = "LaLaLaLaLaAlAlAlAl";
            $var3 = $var1($var2);
            $var4 = strtolower($var2);
            

            $var3 and $var4 will be the same...

            Let's take $var3... it is defined like this : $var1($var2)

            It takes the value of $var1 and it gives : strtolower($var2)

            It then calls the strtolower() function and passes $var2.

            In short, when you have a variable before a "(", it replaces that variable with its value and calls the function having the name of the value.

            So, if you use $COOKIE(...), the value returned by $COOKIE is an array, so it can't work..

            Is it clear ? (I don't think... !)

              k, i have another question..

              i have this script to check to see if the person is logged in or not. did i do it right? i'm thinking i didnt, because when i log in then goto the members page (where the script is) it says i'm not logged in.

              <?php
                  $_COOKIE['username'];
                  if(empty($_COOKIE['username'])) {
                      die('
              An error has ocurred. It may be that you have not logged in, or that
              your session has expired.  Please try <a href="/">logging in</a> again or 
              <a href="/?HNC=register">Register</a><br /><br />
              
              For further questions email the <a href="mailto:Mark00018@hotmail.com">Web Master</a>
              ');
                  }
              ?>
              

                To check if a cookie is set is very easy...

                <?
                 if(isset($_COOKIE["the_name_of_the_cookie"])) {
                      // the cookie is set
                 } else {
                      // the cookie isn't set
                 }
                ?>
                

                  i get this error

                  Parse error: parse error, unexpected '{' in C:\Documents and Settings\Administrator\Desktop\HazardNet\login\logincheck.php on line 2

                  with this:

                  <?php
                     if(isset($_COOKIE['username']){
                     $loggedin = "yes";
                     }
                     else{
                          die('
                  An error has ocurred. It may be that you have not logged in, or that
                  your session has expired.  Please try <a href="/">logging in</a> again or 
                  <a href="/?HNC=register">Register</a><br /><br />
                  
                  For further questions email the <a href="mailto:Mark00018@hotmail.com">Web Master</a>
                  ');}
                  ?>

                    oops, forgot a ) sorry

                    even so, its saying i'm not logged in, so is it not setting the cookie?

                      Are you sure you set the cookie before ?!

                        does $_COOKIE['username'] set a cookie? or do i HAVE to use setcookie("username", username) to set it..?

                        p.s. sorry for being a nuisance

                          $COOKIE only returns the value of a cookie. You can't set a cookie by doing $COOKIE["new_cookie"]... remember that a cookie is a header sent to he user... So but adding a new value to $_COOKIE, you won't send a header... So, you have to use setcookie().

                            its still not working.. i'll post my code here, maybe someone can help me..

                            logincheck.php

                            <?php
                                $_COOKIE['username'];
                                if(empty($_COOKIE['username'])) {
                                    die('
                            An error has ocurred. It may be that you have not logged in, or that
                            your session has expired.  Please try <a href="/">logging in</a> again or 
                            <a href="/?HNC=register">Register</a><br /><br />
                            
                            For further questions email the <a href="mailto:Mark00018@hotmail.com">Web Master</a>
                            ');
                                }
                            ?>

                            login.php

                            <?
                              if($affected_rows == 1){
                              setcookie("username", username);
                              setcookie("passwd", passwd);}
                              $passwd = md5($passwd);
                              if(!empty($HNC))
                              {
                              	include("$HNC.txt");
                              }
                            ?>
                            
                            //more site layout
                            
                            <?
                            $dbuser = '****';
                            $dbpass = '****';
                            
                            //connect to the DB and select the database
                            $connection = mysql_connect('localhost', $dbuser, $dbpass) 
                            or die(mysql_error()."
                            
                            //more site layout
                            
                            ");
                            
                            mysql_select_db('Hazardnet', $connection) or die(mysql_error()."
                            
                            //more site layout
                            
                            ");
                                //set up the query
                                $query = "SELECT * FROM HN_users
                                        WHERE username='$username' and passwd='$passwd'";
                            
                            //run the query and get the number of affected rows
                            $result = mysql_query($query, $connection) or die('error making query'."
                            
                            //more site layout
                            
                            ");
                            $affected_rows = mysql_num_rows($result);
                            
                            //if there's exactly one result, the user is validated. Otherwise, he's invalid
                            if($affected_rows == 1){
                            print "Thank your for logging in, <strong>$username</strong>, Please continue into the <a href=\"/members/members.php\">members area</a>";
                            }
                            else{
                                print 'Sorry, you seem to have entered an incorrect Username/Password.';
                                }
                            ?>
                            //more site layout
                            		  <?include("user_login.php");?>
                            //more site layout
                            

                            those should be the only 2 things needed. anyone know what i'm doing wrong? why it wont set the cookie (if thats the problem) and why it wont keep them logged in.

                              In logincheck.php, put phpinfo(). It will give you a list of lots of things, and if any cookie is set, you'll see it...

                                how is that gonna help me? oh i get what your saying, but where does it show it

                                  You'll know if the cookies are set.

                                  <?
                                  phpinfo();
                                  ?>
                                  

                                  In the "PHP Variables" section, you'll see something like :

                                  _COOKIE["PHPSESSID"] | e21bf766eee59716e15bdc718e9aaf1a

                                  ( | is simply a separator to represent the cells)

                                    i didnt find anything with _cookie

                                      So it means that cookie aren't set... check your browser settings.