2012-03-02 167 views
-7

可能重复:
Cookies on localhost with explicit domainCookie在本地主机上工作吗?

这是我的代码在用户登录后:

setcookie("user",$entered_username, time()+(60*60*5)); 
    setcookie("password",$entered_password, time()+(60*60*5)); 
    header('Location: frontpage.html'); 

这是我在frontpage.html代码:

<!DOCTYPE HTML> 
<html> 
<head> 
<?php 
if (isset($_COOKIE["user"])) 
    echo $_COOKIE["user"] ; 
else 
    echo "Welcome guest"; 
?> 
</head> 
<body> 

</body> 
</html> 

这不适用于我的本地主机?问题是什么?

+2

5谷歌搜索的秒了我: http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain – Zipper 2012-03-02 23:31:57

+2

PHP代码没有内部.html文件评估(由默认)。你确定它确实在运行,而不是直接在页面上输出PHP代码吗? – pjumble 2012-03-02 23:32:11

+3

请不要将密码保存在cookie中 – 2012-03-02 23:34:58

回答

0

是的,他们在本地主机上运行。组成一个域并将其插入到/ etc/hosts中。在我的PC上,我有C:\ Windows \ System32 \ drivers \ etc等一系列主机进行开发。

+0

为什么不能正常工作呢?我的代码有问题吗? – user1244153 2012-03-02 23:40:33

+0

确保您的配置是正确的,并更改扩展名。 – 2012-03-02 23:42:03

+0

我该怎么做? – user1244153 2012-03-02 23:43:11

2

httpd.conf

<VirtualHost *:80> 
    ServerName wibble.com 
    DocumentRoot "some directory" 
<VirtualHost> 

<Directory "the same directory"> 
    Options Indexes FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory> 

而且

LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll" 

主机(C:\Windows\System32\drivers\etc

增加一个适当的线

例如。

127.0.0.1 myhost.wibble.com 
相关问题