【发布时间】:2015-07-08 08:23:32
【问题描述】:
我已将我的网站从 apache 移动到 nginx,但现在我的网站不想在我的用户尝试登录网站时向他们发送 cookie(或启动会话)。
这是我的登录脚本:
<?php
session_start();
include("includes/config.php");
$naam = mysql_real_escape_string($_POST["naam"]);
$wachtwoord = md5(mysql_real_escape_string($_POST["wachtwoord"]));
if (strlen($naam) > 0)
{
if (strlen($wachtwoord) > 0)
{
$uQuery = mysql_query("SELECT * FROM users WHERE username = '".$naam."' AND password = '".$wachtwoord."' LIMIT 1");
if (mysql_num_rows($uQuery))
{
while($lid = mysql_fetch_array($uQuery)) {
$id = $lid["id"];
}
$_SESSION["lid"] = $id;
header("Location: me.php");
} else {
header("Location: index.php?error=1");
}
}
}
?>
这是我用来连接 MySQL 的(我的配置文件):
<?php
$host = "ip address";
$username = "root";
$password = "password";
$db = "test";
$con = mysql_connect($host, $username, $password);
if (!$con){ die('Verbinding mislukt: ' . mysql_error()); }
$db = mysql_select_db($db, $con);
if (!$db){ die ('Kan database niet vinden: ' . mysql_error()); }
?>
有人知道怎么解决吗?
这是我的 nginx 配置:
#
# The default server
#
server {
listen 80 default_server;
server_name ;
#charset koi8-r;
#access_log logs/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html/shine;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/shine;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
谢谢!
【问题讨论】:
-
PHP 以前如您所说的那样工作,所以没关系。您应该向我们提供配置文件
-
之前一切正常,我使用的是相同的 PHP 版本。我已经测试了我的网站和 MySQL 服务器之间的连接,并且运行良好..
-
我已经编辑了帖子。 :)
-
当我尝试登录时,登录页面接受我的用户名和密码,并将我重定向到您登录时将重定向到的页面。成功登录后的页面重定向我回到我没有登录的错误的索引。
-
我从您问题的第一阶段就知道这一点。你的 PHP 代码没问题。你在你的 ngnix 配置中遗漏了一些东西。看,here,这些就是我们需要的东西。你的 ngninx 配置。
标签: php apache session cookies nginx