home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / funcremovecook.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.2 KB  |  32 lines

  1. function to remove cookies set as array 
  2.  
  3. if you have a cookie whose name is mycookie[myindex2] and mycookie[myindex1] this function will delete all of them. I used "for" loops because I am used to them. A while/list would be prettier though. 
  4.  
  5.  
  6. <?php 
  7.  
  8.      // This is pretty simple.  There are no arguments.  
  9.      //  Once this function is finished the string $final   
  10.      //  will echo the cookies that have been deleted 
  11.  
  12.      
  13.     function clear_cookies(){ 
  14.         global $HTTP_COOKIE_VARS; 
  15.         $cookie_count = count($HTTP_COOKIE_VARS); 
  16.         for($i = 0; $i<$cookie_count; $i++){ 
  17.             $current_cookie = current($HTTP_COOKIE_VARS); 
  18.             $cookie_name = key($HTTP_COOKIE_VARS); 
  19.  
  20.             $current_cookie_count = count($current_cookie); 
  21.             for($c = 0; $c < $current_cookie_count; $c++){         
  22.                 $val = current($current_cookie); 
  23.                 $cookie_to_delete = $cookie_name. "[".$val. "]"; 
  24.                 setcookie($cookie_to_delete); 
  25.                 $final .=  "Deleting . . . $cookie_to_delete<BR>\n"; 
  26.                 next($current_cookie); 
  27.                 } 
  28.             next($HTTP_COOKIE_VARS); 
  29.             } 
  30.         } 
  31. ?>
  32.