簡體   English   中英

Cookie不起作用,apache到nginx

[英]Cookies don't work, apache to nginx

我已將我的網站從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;
#}
}

謝謝!

謝謝你的幫助。 我找到了解決這個問題的方法。 cookie保存文件夾不存在,沒有正確的cmod ..

這個命令解決了它:

mkdir / var / lib / php / session chmod -R 777 / var / lib / php / session

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM