Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 饼干不';t work,apache到nginx_Php_Apache_Session_Cookies_Nginx - Fatal编程技术网

Php 饼干不';t work,apache到nginx

Php 饼干不';t work,apache到nginx,php,apache,session,cookies,nginx,Php,Apache,Session,Cookies,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["wacht

我已经将我的网站从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");
        }
    }
}
?>
谢谢

谢谢你的帮助。 我已经找到了解决办法。 cookie保存文件夹不存在,并且没有正确的cmod

这个命令解决了这个问题:

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

php以前就像您所说的那样工作,所以它还可以。您应该向我们提供配置文件,所有这些都可以使用,我使用的是相同的PHP版本。我已经测试了我的网站和MySQL服务器之间的连接,效果很好。我已经编辑了这篇文章。:)当我尝试登录时,登录页面接受我的用户和密码,并将我重定向到您登录时将重定向到的页面。成功登录后,您看到的页面将我重定向回索引,错误是我没有登录。我从您问题的第一阶段就知道这一点。你的PHP代码还可以。您在ngnix配置中遗漏了一些内容。听着,这些是我们需要的。您的ngninx配置。
<?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()); } 
?>
#
# 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;
#}
}