I
I
Ingvar Von Bjork2019-09-26 11:43:19
1C-Bitrix
Ingvar Von Bjork, 2019-09-26 11:43:19

How to fix session write problem?

From the js file using ajax, a variable is passed to write to the session and this variable is returned from the session:

$.ajax({
    type: 'POST',
    url: siteTemplate + '/vision/vision.php',
    data: {
      vision: 'test'
    },
    success: function(data){
      console.log(data);
    }
  });

session_start();
$_SESSION['vision'] = $_POST['vision'];
echo $_SESSION['vision'];

And it seems that there are no problems - the necessary text is displayed in the console, but if you access the session from the page code, the session will return without ['vision']. It seems that Bitrix is ​​rewriting the session. How can this be bypassed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-09-26
@DeboshiR

require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
$_SESSION['vision'] = $_POST['vision'];
echo $_SESSION['vision'];
require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_after.php');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question