Board logo

標題: [疑難] PHP cookie 問題 [打印本頁]

作者: saxontse    時間: 2009-5-4 16:30     標題: PHP cookie 問題

小弟最近用PHP寫一個網站,現正寫有關login 部份,但我不知道是甚麼原因令這部份未能完成。 以下是我所寫的code
<?

include("CONNECT.php");

$UN = "test";

$PWD = "test";

$result= mysql_query("select * from user_info where u='$UN' and p='$PWD'");

$number = mysql_num_rows($result);


if ($number == 0)

{
echo "登入失敗!!找不到這個帳號或密碼!!";

exit;

}

elseif ($number > 0)

{
$FO = mysql_fetch_object($result);

setcookie ("LN", $UN, time()+(60*60*24));


if(isset($_COOKIE['LN']))


print "<p>OK</p>";

else

print "<p>Not OK</p>";

}

?>

就我自己所看我完全看不出那裡出了問題。請問會是web hosting 的問題嗎? 因為我用的是免費的web hosting (www.700megs.com, www.free-site-host.com),若果是這樣的話有別的web hosting 可以提供嗎? 若果不是,那會是甚麼問題呢? 請指教,謝謝!
作者: 9inches    時間: 2009-5-6 15:25

see http://hk2.php.net/manual/en/function.setcookie.php
<?php
// set the cookies
setcookie("cookie[three]""cookiethree");
setcookie("cookie[two]""cookietwo");
setcookie("cookie[one]""cookieone");

// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
    foreach (
$_COOKIE['cookie'] as $name => $value) {
        echo 
"$name : $value <br />\n";
    }
}
?>



Cookie = data stored in brower; to be set by 1) javascript or 2) server
and will be sent to server when requesting new page . Therefore 
$_COOKIE['LN'] will contain value until you reload the server page.




歡迎光臨 香港 Xocat Forum 討論區 (http://p.xocat.com/p/) Powered by Discuz! 6.0.0