PHP session is lost after submit

It does not make sense. It works in localhost, but not on my server.

Before submitting the form, if I am var_dump() $_SESSION, it returns me the following:

array(2) { ["email"]=> string(40) "082b6eff9db5019e6a28f586a679b7f72fab27f4" ["id"]=> int(5) }

The form is as follows:

<form method='POST' action='response.php?type=add_customer'>
    <input type='text' name='customer'/>
    <input type='submit' value='add'/>
</form>

If I'm var_dump() $_SESSIONon response.php , I get:array(0) { }

if(!isset($_SESSION)){ session_start(); }
var_dump($_SESSION);

How is this possible?

Because it works localhost, but not on my server. Maybe this is php.ini problem? If so, then what?

EDIT (1) : changed my code to this (in response.php ):

session_start();

if(isset($_REQUEST['type'])){
    switch ($_REQUEST['type']){
       case 'add_customer': 
        var_dump($_SESSION);
        break;
    }
}

Still working. It retrieves an empty array.

EDIT (2): Allowed. If anyone could explain to me why this:

session_start();
var_dump($_SESSION); // doesn't work
print_r($_SESSION); // doesn't work
echo $_SESSION['id']; // works

I value. Because the problem was this.

+4
source share
3

session_start(); <?php , $_SESSION

+2

GET POST.

<form method="POST" action="response.php">
    <input type="hidden" name="type" value="add_customer" />
    <input type="text" name="customer" />
    <input type="submit" value="add" />
</form>
0
session_start();
print_r($_SESSION);

. ( <? php , , , ( , bom ..)
.

, , , . , - / / .

, / ?

if(isset($_REQUEST['type'])){

1:. :
www. 777 .

<?php
session_save_path('/home/project/www/sessions');
ini_set('session.gc_probability', 1);
session_start();
print_r($_SESSION);
?>

, -

0

Source: https://habr.com/ru/post/1524677/


All Articles