setcookie

 

目錄

  • Set & Get Cookie
  • Session Cookie

 


Set & Get Cookie

 

set cookie

<?php
  setcookie("mytest", 1234);
?>

get cookie

<?php
  if(!isset($_COOKIE["mytest"])) {
    echo "without set mytest";
  }
?>

Test

curl -I https://IP/my.php

應用

.htaccess

Header edit Set-Cookie "^(PHPSESSID)=(.*)$" "$1=$2; SameSite=Strict"

 


Session Cookie

 

php 保儲 Cookie 的位置

grep session.save_path /etc/httpd/conf.d/php.conf

    php_value session.save_path    "/var/lib/php/session"

複製 Session

1) 查看自己的 Session ID

Firefox: F12 > Storage > Cookies

Info

Expires: Session
Name: PHPSESSID 的 Value

2) Copy 別人的 Session

cp -a sess_???? sess_VALUE