【问题标题】:Do cookies work on a localhost? [duplicate]cookie 在本地主机上工作吗? [复制]
【发布时间】:2012-03-21 11:02:00
【问题描述】:

可能重复:
Cookies on localhost with explicit domain

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

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>

这在我的 wamp 本地主机上不起作用?有什么问题?

【问题讨论】:

  • 5 秒的谷歌搜索让我明白了:stackoverflow.com/questions/1134290/…
  • PHP 代码不在 .html 文件中进行评估(默认情况下)。你确定它实际上是在运行而不是直接在页面上输出 PHP 代码吗?
  • 请不要将密码存储在cookie中

标签: php html cookies


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    是的,它们在本地主机上工作。组成一个域并将其放入 /etc/hosts。在我的 PC 上,我有 C:\Windows\System32\drivers\etc 以及许多用于开发的主机。

    【讨论】:

    • 为什么它不起作用呢?我的代码有问题吗?
    • 确保您的配置正确,并更改扩展名。
    猜你喜欢
    • 2015-03-20
    • 2021-01-27
    • 2012-03-26
    • 2021-11-12
    • 2014-03-11
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多