作者tas72732002 (蔥頭)
看板PHP
標題[請益] 子母視窗相互取得資訊問題
時間Fri Jun 29 17:55:25 2012
母視窗:
window.open("abc.html", "login_window", "height=400, width=400, top="+top+", left="+left+", toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
echo $_COOKIE["test_cookie"];
子視窗:
setcookie("test_cookie","123456",time()+3600,"/");
問題:子視窗所存的cookie,母視窗一直無法取的,一值是空的
PS:母視窗與子視窗是處在不同的目錄下,同個網域
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.208.83.253
1F:→ kerash:php?? html ?? 06/29 18:03
2F:→ tas72732002:php 06/29 18:03
3F:→ tas72732002:頁面reload 仍無法取得 06/29 18:03
4F:→ kerash:所以你open html? 06/29 18:03
5F:→ kerash:有rewrite過嗎? 06/29 18:04
6F:→ tas72732002:我寫錯 open的子視窗也是php的頁面 06/29 18:07
7F:→ kerash:setcookie 第四個參數是拿來設定 path 的 06/29 18:09
8F:→ kerash:原domain=> www.domain.com/ 設定的 cookie 若在底下dir中 06/29 18:09
9F:→ kerash:如 www.domain.com/dir1/t2.php 設定 cookie 的話 06/29 18:10
10F:→ kerash:那在設定時要把 setcookie 第4個參數設 "/" 表主目錄下共用 06/29 18:10
11F:→ kerash:否則 cookie 的 path 是會在你 /dir1 底下共用, / 抓不到 06/29 18:11
12F:→ tas72732002:第四個參數我有設定/ 06/29 18:14
13F:→ tas72732002:還是抓不到 06/29 18:14
14F:→ tas72732002:第五個參數應該不用 06/29 18:15
15F:→ tas72732002:因為我是同個網域 06/29 18:15
16F:→ kerash:我測試下是可以,你用 chrome開F12找resource的cookie吧 06/29 18:15
17F:→ kerash:記得cookie設定之前不能有header輸出 06/29 18:16
18F:→ kerash:要在最前面才有效 06/29 18:16
19F:→ tas72732002:chrome有,但就是取不到.........y 06/29 18:26
20F:→ tas72732002:發現expire time 是1969........ 寫入是正確的時間~~~ 06/29 18:59
21F:→ tas72732002:setcookie("test","123456",$now+3600,"/"); 06/29 19:04
22F:→ tas72732002:這有問題嗎? 06/29 19:05
23F:推 kerash:now是多少... ? 他是算秒數所以+3600應該沒問題 06/29 21:44
24F:→ tas72732002:取得time()的時間+3600 06/30 11:26
25F:→ tas72732002:應該沒有問題,chrome expire time是1969年 06/30 11:27
26F:→ kerash:expire time 是 1969 年就有問題啦... 你的code只有這樣嗎? 06/30 16:49
27F:→ kerash:你直接把$now改成time寫在裡面試試看 06/30 16:50