My sessions aren’t working. Everytime I reload the page it generates a new session id and deletes all session variables.. I am not sure if there is an error in my code or in my configuration. I am using MAMP on Mac as local server software with php 5.2.17
Every php file includes the layout_top.php at first. the layout_top starts the session every time:
<?php
        session_start();
    ?>
also there is a log in site like this:
<?php
include 'layout_top.php';
include 'db_connect.php';
$username = $_POST["li_username"]; 
$pw = $_POST["li_passwort"];
    if ($username == "" || $pw == "") {
        echo "Fülle bitte alle Felder aus!";
        }
    else {
        $check_pw_query = mysql_query("SELECT password FROM user WHERE username = '$username'") or die(mysql_error());
        $check_pw = mysql_fetch_assoc($check_pw_query);
        if ($pw == $check_pw{'password'}) {
            echo "Juhu! </br>";
            $first_name_query = mysql_query("SELECT first_name FROM user WHERE username = '$username'") or die(mysql_error());
            $first_name = mysql_fetch_assoc($first_name_query);
            $second_name_query = mysql_query("SELECT second_name FROM user WHERE username = '$username'") or die(mysql_error());
            $second_name = mysql_fetch_assoc($second_name_query);        
            $id_query = mysql_query("SELECT id FROM user WHERE username = '$username'") or die(mysql_error());
            $id = mysql_fetch_assoc($id_query);
            if (!isset($_SESSION['username'])) {
                $_SESSION['username'] = $username;
            }
            if (!isset($_SESSION['first_name'])) {
                $_SESSION['first_name'] = $first_name{'first_name'};
            }    
            if (!isset($_SESSION['second_name'])) {
                $_SESSION['second_name'] = $second_name{'second_name'};
            }
            if (!isset($_SESSION['id'])) {
                $_SESSION['id'] = $id{'id'};
            }
            if (!isset($_SESSION['gender'])) {
                $_SESSION['gender'] = $gender{'gender'};
            }
        }
    }
There it sets the session variables.. but if I reload the page all session variables are gone. Hope you understand my problem. Thanks for helping.
EDIT: Here is the phpinfo(), maybe this will help finding the problem..
session.auto_start          Off Off
session.bug_compat_42   On  On
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  100 100
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character|4   4
session.hash_function   0   0
session.name            PHPSESSID|PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /Applications/MAMP/tmp/php  /Applications/MAMP/tmp/php
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    Off Off
session.use_trans_sid   0   0
EDIT 2:
Strict Standards: session_start() [function.session-start]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /Applications/MAMP/htdocs/network/layout_top.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/htdocs/network/layout_top.php:1) in /Applications/MAMP/htdocs/network/layout_top.php on line 6
Strict Standards: session_start() [function.session-start]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /Applications/MAMP/htdocs/network/layout_top.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/htdocs/network/layout_top.php:1) in /Applications/MAMP/htdocs/network/layout_top.php on line 6
 
     
     
     
    