首页 > 解决方案 > PHP Session 不适用于某些(有时)移动用户?

问题描述

我正在为用户 orderid (siparisno) 创建会话,一些用户收到错误

“你没有订单号”。

使用 php7

//function1
//creating orderid(siparisno)
$rand1=rand(10,99);
$rand2=rand(10,99);
$rand3=rand(10,99);
$siparisno_manuel=date("dmy").strtotime("now").$rand1.$rand2.$rand3;
$siparisno=$siparisno_manuel;
$_SESSION["siparisno"]=$siparisno;

//function2
//getting orderid
@ob_start();
include __DIR__ . '/../view/success.php';
$buffer=@ob_get_clean();
$siparisno=$_SESSION["siparisno"];//GETTING HERE SESSION
if ($siparisno==null){
    $string="<h3>Your order number could not be created. Please repeat your order.(error_code: $siparisno)</h3>";
    $buffer=str_replace("{string}",$string,$buffer);
    echo $buffer;
}else{
    //create order with orderid
}

一些安卓用户得到

“无法创建您的订单号。请重复您的订单 (error_code:)”

用户:“Mozilla/5.0 (Linux; Android 8.0.0; SM-A520F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.111 Mobile Safari/537.36”

标签: phpsession

解决方案


缺少 session_start() 页面顶部,如果您用于restapi,则无法将数据存储到会话,因为会话是无状态的......

seesion_start();

英吉利斯姆布卡达尔


推荐阅读