我試着找到我的問題的解決方案的谷歌搜索。用`curl_setopt`在onether文件中設置cookie等
我需要在一個不同的文件中設置一個cookie,我試着用curl_setopt
,但它不起作用。
任何方式的想法是用PHP發送到設置cookie的另一個網頁的價值,這樣的事情:
file1.php
<? //start php
//at the begining of the file i have
session_start();
header('Content-Type: text/html; charset=utf-8');
//if i set a cookie now it give me an error cause i can not change the header
//but because i need to set a cookie now without leaving this file
//i tryed to set it in file2.php this way:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $SITE_HOME_DIR ."login.php");
// Do a POST
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '[email protected]');
curl_close($ch);
///end php
?>
file2.php
<?
//just set cookie
setcookie("TestCookie", $_POST['email'], time()+3600)
?>
但這doesn'work ....
任何想法?謝謝。
你需要說明你的「不同的文件」或「其他頁面」的概念。 Cookie通常設置爲['setcookie'](http://php.net/setcookie),而不是['curl_setopt'](http://php.net/curl_setopt)。 – mario 2012-01-05 20:35:05
好的我編輯了我的問題... – 2012-01-05 21:12:31
仍然不清楚你的實際目標是什麼。在第一個文件中使用'setcookie'有什麼問題?解釋你如何期望這種行爲在哪個環境下進行。 (編輯後的代碼沒有任何說明。) – mario 2012-01-05 21:14:40