【问题标题】:PHP Session not working on some(times) mobile users?PHP Session 不适用于某些(有时)移动用户?
【发布时间】:2025-11-22 14:05:01
【问题描述】:

我正在为用户 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”

【问题讨论】:

  • 那么session_start()在哪里
  • 您能否展示您的实际代码及其彼此之间的分离(您提到函数,函数定义在哪里,每个函数的调用方式和时间?)
  • 小点 $siparisno=$siparisno_manuel; $_SESSION["siparisno"]=$siparisno;为什么中间变量,没用
  • 不要忽略错误。它们很有用。
  • 欢迎,为了改善您在 SO 上的体验,请阅读 how to askOn Topic question,以及 Question Check listthe perfect question 以及最重要的是如何创建 @ 987654325@和take the tour

标签: php session


【解决方案1】:

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

seesion_start();

Ingilizcem bu kadar ?

【讨论】:

  • Öncelikle cevabın için teşekkür ederim。 session_start(); var hatta tekrar eklemeye çalıştığım için header uyarısı verdi。 Amamalesef bazı kullanıcılarda 会议 oluşmuyor。 Yani şöyle bahsedeyim üyenin kart bilgilerini post ediyorum bir sayfaya orda session oluşturuyorum siparisno diye sonra üye 3d 安全 sayfasına yönlendiriliyor。 Sms'ine gelen şifreyi girdikten sonra bizim sayfamıza tekrar yönleniyor ama yönlendikten sonra session (siparisno) oluşmadığı için adamın siparişini oluşturamıyorum。 Müşterilerin %98' inde sorun yokken bazılarında bu question oluyor genellikle android kullanıcıları.
  • Session nasil olusur stateless nedir statesfull kavramlari be header ile aciklarsak daha konu tam oturur stateless her request bilgi gonderilir mesela rest apilerde session tutamazsin php Ile istesende tutamaz peki nasil olursa php her seferinde sessionu tutar headerden gelen data ile php onu okur boylece sessionu 用户 bilgilerini tutar artik 她的 seferinde kullanici bilgisini gondermeye gerek yok session kullanici bilgilerini tutar bunada statesfull denir bu asamada Boyle hatta almis olabilirsin ...kullanici cok ise sessionlari redise yazdirmayi dene
最近更新 更多