Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie is not being set!

    PHP Code:
    <?
    include 'sql.php';  

        
    $username=$_POST["username"];
        
    $query "SELECT * FROM users WHERE username = '$username'";
        
    $result mysql_query($query$link) or die("Query Failed!2");
        
    $password=$_POST["password"];
    if (
    $line mysql_fetch_array($resultMYSQL_ASSOC) ==''){
               echo 
    "<html><head><title>Login: Devastation</title></head><center><font color='white'>User $username not found in database!";
              }else{
        
    mysql_free_result($result);
        
    $result mysql_query($query$link) or die("Query Failed!3");
            
    $row mysql_fetch_assoc($result);
        if (
    $password == $row["password"]){
        
    $id=$row['id'];
        
    mysql_query("delete from online where id='$id'"$link) or die("Yeah");
        
    mysql_query("insert into online values ('$id', '$tm')"$link) or die("Query Failed!4");
        
    setcookie('Dev'$idtime()+3600);  
        
    $herm $_COOKIE["Dev"];
        
    $type=$row['type'];

    print 
    "<iframe name='I1' width='100%' height='90%' src='main.php' align='center' border='0' frameborder='0'>
    Your browser does not support inline frames or is currently configured not to display inline frames.
    </iframe>"
    ;


    print 
    "<center><p align='bottom'><font size='1' color='white'><a href='main.php?link=home' target='I1'>Home</a> - <a href='main.php?link=prefs' target='I1'>Preferences</a> - <a href='main.php?link=leave' target='I1'>Leave Form</a> -";if($type=='1'){print "<a href='main.php?link=admin' target='I1'>Admin</a> - ";}print " <a href='main.php?link=logout' target='I1'>Logout</a>";
        
        }else{
        Print 
    "<center><font color='white'>Invalid Password, try again!<br>";
        }}

        
    mysql_free_result($result);

        
    mysql_close($link);
    Its not creating a Cookie from what I see... on my main.php page here is what I have set up...

    PHP Code:
    <?
    /*Reset Cookie to prevent loggout*/
    $id=$_COOKIE["Dev"];

    /* Chech to see if Logged Out */
    if ($id == ""){
    setcookie ("Dev"""time()-3600);
    print 
    "<html><body><center><h2>YOU ARE LOGGED OUT1</h2></center></body></html>";
    exit;
    }else{
    include 
    'sql.php';
    $result mysql_query("SELECT id FROM online where id=$id" $link) or die("Query1 failed");
    $row mysql_fetch_assoc($result);
    if (
    $row["id"]!=$id){
    setcookie ("Dev"""time()-3600);
    print 
    "<html><body><center><h2>YOU ARE LOGGED OUT2</h2></center></body></html>";
    exit;
    mysql_close($link);
    }}
    I spent about 5 hours last night trying to get this to work... advice would be appreciated!

    -Nate

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    The cookie has not been set...because you're setting in the past.

    setcookie ("Dev", "", time()-3600); // here you are saying cookie has expired an hour ago

    Basically, when you want to delete a cookie...you set it to a date past today's date...and it would be deleted automatically.

    so...change the above statement to the following and it should work for an hour
    setcookie ("Dev", "", time()+3600);// cookie is active for an hour

    hope that helps.
    ess

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You misread it, the first php page I put on is the page that sets the cookie! The main.php page (2nd php page) sets it negative time when no Variable ID is found, deminishing the cookie. Hence the check to see if the cookie exists! No cookie is being created!

  • #4
    New to the CF scene
    Join Date
    Oct 2006
    Location
    Belgium
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    instead of

    PHP Code:
    setcookie('Dev'$idtime()+3600); 
    try

    PHP Code:
    $host $_SERVER['HTTP_HOST'];
    setcookie('Dev'"$id"time()+3600"/""$host"); 
    had the same problem once and this solved it.

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    freaking awsome! That worked perfectly... thank you very much!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •