admin管理员组文章数量:1130349
I am defining $_SESSION['session_test'] from $_POST['reason'] I get from AJAX call.
Inside of this function, $_SESSION['session_test'] does get defined, and I get desired echo result.
add_action('wp_ajax_return_reason', array( __CLASS__ , 'select_return_reason'));
static function select_return_reason() {
$_SESSION['session_test'] = $_POST['reason'];
echo "REASON: " . $_SESSION['session_test'];
echo "<br>";
wp_die();
}
But, when I refresh page and try to echo $_SESSION['session_test'] in some other function below this one, it's empty - I get NULL.
add_action('woocommerce_after_cart_table', array( __CLASS__ , 'display_returned_items'));
static function display_returned_items() {
echo "Testing: " . $_SESSION['session_test'];
}
Why $_SESSION['session_test'] value is available/defined only inside function which is executed by AJAX?
My session_start(); is on the top of the php file, right after the <?php opening tag.
Please let me know if I should provide more info. Thanks.
I am defining $_SESSION['session_test'] from $_POST['reason'] I get from AJAX call.
Inside of this function, $_SESSION['session_test'] does get defined, and I get desired echo result.
add_action('wp_ajax_return_reason', array( __CLASS__ , 'select_return_reason'));
static function select_return_reason() {
$_SESSION['session_test'] = $_POST['reason'];
echo "REASON: " . $_SESSION['session_test'];
echo "<br>";
wp_die();
}
But, when I refresh page and try to echo $_SESSION['session_test'] in some other function below this one, it's empty - I get NULL.
add_action('woocommerce_after_cart_table', array( __CLASS__ , 'display_returned_items'));
static function display_returned_items() {
echo "Testing: " . $_SESSION['session_test'];
}
Why $_SESSION['session_test'] value is available/defined only inside function which is executed by AJAX?
My session_start(); is on the top of the php file, right after the <?php opening tag.
Please let me know if I should provide more info. Thanks.
Share Improve this question asked Nov 12, 2018 at 10:51 Tahi ReuTahi Reu 3081 silver badge14 bronze badges1 Answer
Reset to default 1Wrapping this line inside if statement solved the problem:
if(!isset($_SESSION['session_test'])) {
$_SESSION['session_test'] = $_POST['reason'];
}
I thought select_return_reason(){...} function which is holding this line was executing only by AJAX, not on each page load.
I am defining $_SESSION['session_test'] from $_POST['reason'] I get from AJAX call.
Inside of this function, $_SESSION['session_test'] does get defined, and I get desired echo result.
add_action('wp_ajax_return_reason', array( __CLASS__ , 'select_return_reason'));
static function select_return_reason() {
$_SESSION['session_test'] = $_POST['reason'];
echo "REASON: " . $_SESSION['session_test'];
echo "<br>";
wp_die();
}
But, when I refresh page and try to echo $_SESSION['session_test'] in some other function below this one, it's empty - I get NULL.
add_action('woocommerce_after_cart_table', array( __CLASS__ , 'display_returned_items'));
static function display_returned_items() {
echo "Testing: " . $_SESSION['session_test'];
}
Why $_SESSION['session_test'] value is available/defined only inside function which is executed by AJAX?
My session_start(); is on the top of the php file, right after the <?php opening tag.
Please let me know if I should provide more info. Thanks.
I am defining $_SESSION['session_test'] from $_POST['reason'] I get from AJAX call.
Inside of this function, $_SESSION['session_test'] does get defined, and I get desired echo result.
add_action('wp_ajax_return_reason', array( __CLASS__ , 'select_return_reason'));
static function select_return_reason() {
$_SESSION['session_test'] = $_POST['reason'];
echo "REASON: " . $_SESSION['session_test'];
echo "<br>";
wp_die();
}
But, when I refresh page and try to echo $_SESSION['session_test'] in some other function below this one, it's empty - I get NULL.
add_action('woocommerce_after_cart_table', array( __CLASS__ , 'display_returned_items'));
static function display_returned_items() {
echo "Testing: " . $_SESSION['session_test'];
}
Why $_SESSION['session_test'] value is available/defined only inside function which is executed by AJAX?
My session_start(); is on the top of the php file, right after the <?php opening tag.
Please let me know if I should provide more info. Thanks.
Share Improve this question asked Nov 12, 2018 at 10:51 Tahi ReuTahi Reu 3081 silver badge14 bronze badges1 Answer
Reset to default 1Wrapping this line inside if statement solved the problem:
if(!isset($_SESSION['session_test'])) {
$_SESSION['session_test'] = $_POST['reason'];
}
I thought select_return_reason(){...} function which is holding this line was executing only by AJAX, not on each page load.
本文标签: plugin developmentSESSION inside php function executed by AJAX
版权声明:本文标题:plugin development - $_SESSION inside php function executed by AJAX 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749190647a2330135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论