I have moved my website from apache to nginx, but now I have the problem that my website doesn't want to send cookies (or start a session) to my users when they try to log in on the website.
This is my log in script:
<?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");
}
}
}
?>
This is what I'm using for connecting to MySQL (My config file):
<?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()); }
?>
Does someone know how to fix it?
Here's my nginx config:
#
# 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;
#}
}
Thanks!