# What's Up With My PHP Sessions?

**URL:** <https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920>\
**Category:** programming\
**Created:** [July 14, 2008, 4:24pm UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920 "2008-07-14T16:24:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NathanZachary](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@NathanZachary](https://forum.kirupa.com/u/NathanZachary)\
**Post date:** [July 14, 2008, 4:24pm UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920/1 "2008-07-14T16:24:10Z")

</div>

Hello World;

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

I have two pages (So far 😉 ). 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

```php
start_session();

```

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

```php
$_SESSION['Lang']

```

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

```php
$_SESSION['Lang']

```

on Contact.php. (I have already written the

```php
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

```php
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.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 14, 2008, 4:59pm UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920/2 "2008-07-14T16:59:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NathanZachary](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@NathanZachary](https://forum.kirupa.com/u/NathanZachary)\
**Post date:** [July 15, 2008, 8:38am UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920/3 "2008-07-15T08:38:24Z")

</div>

> [@sekasi;2358396](#):
>
> 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
<?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

<?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

---

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [July 15, 2008, 10:30am UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920/4 "2008-07-15T10:30:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NathanZachary](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@NathanZachary](https://forum.kirupa.com/u/NathanZachary)\
**Post date:** [July 15, 2008, 10:53am UTC](https://forum.kirupa.com/t/whats-up-with-my-php-sessions/265920/5 "2008-07-15T10:53:50Z")

</div>

> [@Voetsjoeba;2358881](#):
>
> 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.
