Why does the PHP session not work if I already have a variable in the super global $_SESSION?

Asked

Viewed 42 times

1

I have the following code in the file config.php:

<?php
if(session_status() != PHP_SESSION_ACTIVE )
{
    session_start();
}

$_SESSION['id_sessao'] = session_id();

...

It turns out that when I send the login form to insert another data in the session that in that case would be $_SESSION['login'] , this does not occur.

The login page looks like this:

<?php
require_once 'config.php';
...
$login = $_REQUEST['login'];
$_SESSION['login'] = $login;

...

Would you please help me?

  • How did you verify that "it doesn’t work"? You guaranteed that the form value would get correctly to PHP?

  • Yes. I used var_dump($_SESSION); and there I found the value of session_id();

  • Only my variable doesn’t go there. I tested it on localhost and it’s ok, but when I try it online it doesn’t work.

  • The form is submitted via jQuery ajax and I have response from the login.php page in . json format.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.