2012-06-18 130 views
1

我正面臨另一個問題。我在php中建立了一個項目。網址是像「www.mysite.com」 我創建使用example1.php頁面是根目錄下,並在頁面的路徑是setcookie()方法的餅乾... www.mysite.com/in/example1.php無法訪問Cookie

現在我想找回頁面'indix.php'中cookie的值,其網址爲www.mysite.com/index.php,位於文件夾「in」之外。

但在此index.php頁面未找到cookie。 我使用print_r()但沒有找到cookie。

我做了什麼錯誤?請幫幫我。

回答

2

http://php.net/manual/en/function.setcookie.php

範圍的cookie是第四可變( 「路徑」) - 默認爲當前路徑。聽起來你需要將它設置爲服務器根目錄或'/'。

setcookie('mycookie', 'myvalue', 0, '/'); 
+0

非常感謝。它的工作.... –

0

當您設置Cookie

setcookie (string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]]) 

你必須設置$path參數「/」這種方式會在你的網頁隨處可見。另請檢查您的$expire參數。

+0

非常感謝。有用.... –