tags:

views:

38

answers:

2

this is my code in logout.php

    <?php
if(isset($_COOKIE['cookie-username']) || isset($_COOKIE['cookie-password'])) {

    setcookie("cookie-username", NULL, time()-60*60*24*100);
    setcookie("cookie-password", NULL, time()-60*60*24*100);
}
    header( 'Location: ../login' ) ;
    ?>

I can confirm the cookies exist, If I do a while loop I get
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 79 bytes) in /home/ios/public_html/logout.php on line 5

which means It cannot delete the cookies... I've done a lot of googling, but I can't figure out why it won't delete said cookies...

Help? Thanks In Advance

edit: proof of cookies: http://cl.ly/1c31120de4b722518b05

creation of cookies:

if (isset($_POST['submit'])) {

        try {           
            if (!isset($_POST['username']) || !isset($_POST['password']) || trim($_POST['username']) =='' || trim($_POST['password']) =='') {               throw new Exception('All Fields Are Required!');
            }
            $username = strtolower($_POST['username']);
            $password = md5(strtolower($_POST['password']));

            include('classes/config.php');

                        [SQL REMOVED]
            foreach ($pdo->query($sql) as $row) {
                $dbPassword = $row['password'];
            }  

            if (!isset($dbPassword)) {
                throw new Exception('Invalid Username or Password!');
            }

            if ($dbPassword == $password) {
                 if (!isset($_COOKIE['cookie-username']) || !isset($_COOKIE['cookie-password'])){ 

                    $days = 1;

                    if (strtolower($_POST['remember']) == 'on') {
                        $days = 30;
                    }


                    setcookie("cookie-username", $username, time()+60*60*24*$days, "/");
                    setcookie("cookie-password", $password, time()+60*60*24*$days, "/");

                }  

                   echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index">';    
            }   
            else if ($dbPassword != $password) {
                throw new Exception('Invalid Username or Password!');
            }   
        }

            catch (Exception $e) {
                $exception = $e->getMessage();
        }
    }
A: 
<?
setcookie('cookie-username', 0, -1);
setcookie('cookie-password', 0, -1);
header('Location: example.com/path/login');
?>
  1. This functions don't throw anything then try is not usable for you.
  2. $_COOKIES is refreshing only when script start then if you erase cookie, you will see on next refresh results.
Svisstack
same thing happens with that.
tap touch click
+1  A: 

Remove the while loop. setcookie doesn't affect $_COOKIE.

If it doesn't help, try this:

<?php
    setcookie("cookie-username", NULL, time()-60*60*24*100, "/", ".yourdomain.com");
    setcookie("cookie-password", NULL, time()-60*60*24*100, "/", ".yourdomain.com");
    header( 'Location: ../login' ) ;
?>

PS: Also it's a bad idea to store login/password in cookies, for an authentication purpose it's better to store a flag in session

meze
+1 this is it. It's effectively an infinite loop, filling the memory until it crashes.
Pekka
ok, so its infinite, now that I changed it back to just an if statement, it still cannot delete cookie.
tap touch click
it becomes an infinite redirect loop, and the cookies never delete.
tap touch click
updated. if it doesn't help can you show how you set those cookies ? are you sure they still exist in your browser?
meze
I modified the post with more information.
tap touch click