推介:| Web Hosting | 外賣系統 | Server colocation | Web Shop System | Makeup course |

查看完整版本: 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 ([url]www.700megs.com[/url], [url]www.free-site-host.com[/url]),若果是這樣的話有別的web hosting 可以提供嗎? 若果不是,那會是甚麼問題呢? 請指教,謝謝!

9inches 2009-5-6 15:25

see [url=http://hk2.php.net/manual/en/function.setcookie.php]http://hk2.php.net/manual/en/function.setcookie.php[/url]
[font=Consolas][size=11px][color=#00bb]<?php
[/color][color=#ff800]// set the cookies
[/color][color=#00bb]setcookie[/color][color=#0770]([/color][color=#dd00]"cookie[three]"[/color][color=#0770], [/color][color=#dd00]"cookiethree"[/color][color=#0770]);
[/color][color=#00bb]setcookie[/color][color=#0770]([/color][color=#dd00]"cookie[two]"[/color][color=#0770], [/color][color=#dd00]"cookietwo"[/color][color=#0770]);
[/color][color=#00bb]setcookie[/color][color=#0770]([/color][color=#dd00]"cookie[one]"[/color][color=#0770], [/color][color=#dd00]"cookieone"[/color][color=#0770]);

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


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.
頁: [1]
查看完整版本: PHP cookie 問題