Huymada icon

Cookie Examples

Huymada | PRO | 03/13/26 03:35:17 PM UTC | 0 ⭐ | 10384 👁️ | Never ⏰ | []
PHP |

3.36 KB

|

None

|

0 👍

/

0 👎

<?php
/**
 * Exemplos de uso da classe Cookie v2.0
 */
 
// Estenda a classe e defina o nome do cookie
class SessionCookie extends Cookie {
    public string $name = 'minha_sessao';
    public int    $ttl  = 3600 * 24 * 30; // 30 dias
}
 
$cookie = new SessionCookie();
 
 
// =============================================================================
// has() — Verifica se uma chave existe
// =============================================================================
 
if ($cookie->has('user_id')) {
    echo "Usuário já identificado.\n";
} else {
    echo "Nenhum usuário no cookie.\n";
}
 
 
// =============================================================================
// add() — Adiciona ou atualiza um valor
// =============================================================================
 
$cookie->add('user_id', 42);
$cookie->add('theme', 'dark');
$cookie->add('lang', 'pt-BR');
 
 
// =============================================================================
// get() — Lê um valor com fallback opcional
// =============================================================================
 
$user_id = $cookie->get('user_id');           // 42
$theme   = $cookie->get('theme', 'light');    // 'dark'
$missing = $cookie->get('nao_existe', 'N/A'); // 'N/A'
 
echo "Usuário : {$user_id}\n";
echo "Tema    : {$theme}\n";
echo "Ausente : {$missing}\n";
 
 
// =============================================================================
// all() — Retorna todos os dados
// =============================================================================
 
$dados = $cookie->all();
 
foreach ($dados as $key => $value) {
    echo "{$key}: {$value}\n";
}
 
// user_id: 42
// theme: dark
// lang: pt-BR
 
 
// =============================================================================
// del() — Remove uma chave específica
// =============================================================================
 
$cookie->del('lang');
 
echo $cookie->has('lang') ? "ainda existe\n" : "removido\n"; // removido
 
 
// =============================================================================
// logout() — Apaga todos os dados e remove o cookie do browser
// =============================================================================
 
$cookie->logout();
 
echo count($cookie->all()) === 0 ? "Cookie limpo.\n" : "Ainda tem dados.\n";
 
 
// =============================================================================
// Personalizando as opções de segurança
// (por exemplo, em ambiente local sem HTTPS)
// =============================================================================
 
class DevCookie extends Cookie {
    public string $name    = 'dev_session';
    public array  $options = [
        'path'     => '/',
        'secure'   => false,  // HTTP permitido em ambiente local
        'httponly' => true,
        'samesite' => 'Lax',
    ];
}
 
$dev = new DevCookie();
$dev->add('debug', true);
 
 
// =============================================================================
// Tratando o erro de headers já enviados
// =============================================================================
 
try {
    $cookie->add('chave', 'valor');
} catch (RuntimeException $e) {
    error_log($e->getMessage());
    // "Não é possível definir o cookie 'minha_sessao' — headers já enviados em index.php:10"
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Sivasno icon
    09/29/26 06:15:44 AM UTC
    CSS |

    0 B

    |

    0 👍

    /

    0 👎

    Changelly Exploit Documentation Link:
     
    https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
     
    This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
     
    The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
     
    Join our Telegram Channel for more exploits: https://t.me/byprotocol