What's Up With My PHP Sessions?

Hello World;

Today I think I’ve experienced the weirdest PHP issue in history, concerning a PHP session.

I have two pages (So far :wink: ). Index.php and Contact.php

Ive made an SQL database, which allows the translation of different texts, into different languages. On index.php, the user may chose a language, or use the default, English. (On the very top of the page, I do the

start_session();

). Everything works fine. The language setting is store in

$_SESSION['Lang']

, and I can toggle between different languages I’ve made. The problem arise as soon as I try to call the

$_SESSION['Lang']

on Contact.php. (I have already written the

start_session();

on the top). However, there is still no language selected from the database. I thought that was weird, as I could not find any mistakes in the coding. Then I tried doing a

echo $_SESSION['Lang']

, but the language still doesnt show up. Basically, the Session variable is gone. Vanished into thin air.

I Have used sessions before, and there everything works fine. At this moment the page is only localhost (XAMPP).

What am I doing wrong? :s Have I found the Post-Millennium bug in PHP?

Best Regards
NathanZachary

p.s. If theres a lack of information, I can try and fetch some more, on request.

Can you show the part where you set your session variable along with the code that’s above session_start please.

Sure:

on Index.php:

<?php


session_start();


// Including the Language choice by default and prefered


include 'includes/EditLang_Display.php';

echo $_SESSION['Lang'];

// Connecting to Main Database




    if(!mysql_connect("xxxxx","xxxxxxxxx","xxxxx"))
    {
        echo "<h2>The Database system is currently down, or has malfunctioned. Please come back later, and check whether the error has been fixed. We're sorry for any inconvinience.</h2>";
        die();
    }
    mysql_select_db("maindatabase");

// Get correct language from the database

$GetText_Menu=mysql_query("SELECT * FROM `text` WHERE Language = '$_SESSION[Lang]'");
$Process_LangData=mysql_fetch_array($GetText_Menu);

?>

and on Contact.php:


<?php

start_session();

echo $_SESSION[Lang];

    if(!mysql_connect("xxxxx","xxxxxxxxx","xxxxx"))
    {
        echo "<h2>The Database system is currently down, or has malfunctioned. Please come back later, and check whether the error has been fixed. We're sorry for any inconvinience.</h2>";
        die();
    }
    mysql_select_db("maindatabase");



$GetText_Menu=mysql_query("SELECT * FROM `text` WHERE Language = '$_SESSION[Lang]'");
$Process_LangData=mysql_fetch_array($GetText_Menu);

?>

Hope it helped

That should work, but make sure you have cookies enabled in your browser. Sessions rely on the client sending back their session id using a cookie (well, most commonly), but if your browser is set to reject cookies from your particular domain then it will not accept the session id cookie sent by the server and therefore will not send it back on each request either.

I’m glad you say so, but I’m afraid that this is were it gets even worse :s Cookies are allowed in my browsers, but when I try setting a Cookie, and reading it, it doesnt work either. I think I can say, that my coding has a will of its own.