如何在REST客户端应用程序中使用PHP会话? [英] How to use PHP sessions with REST client application ?

查看:93
本文介绍了如何在REST客户端应用程序中使用PHP会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP使用浏览器cookie PHPSESSID来存储会话值(比如说12345),默认情况下,它通过为服务器上的每个会话创建一个文件来实现(session_12345.txt).如果请求不是来自浏览器(例如通过REST协议访问的移动蜂窝应用程序)发出的请求,该怎么办?如果我的其余客户正在发送一个唯一的值来进行自我识别,比如说12345,那么无论如何我可以告诉PHP使用此值来创建session_12345.txt,就好像该值来自cookie PHPSESSID一样?

PHP use browser cookie PHPSESSID to store the session value let say 12345 and it does by creating a file for each session on server by default (session_12345.txt ) . What if the request is coming from not a browser e.g mobile cell application accessing through REST protocol . If my rest client is sending a unique value to identify it self let say 12345 then is there anyway I can tell PHP to use this value to create session_12345.txt as if this value was coming from cookie PHPSESSID ?

先谢谢了.

推荐答案

如果您的会话ID来自与预期会话cookie PHPSESSID不同的来源,则可以使用session_id()方法自己设置会话ID :

If you have your session ID coming in from a different source than the expected session cookie PHPSESSID, you can use the session_id() method to set the session ID yourself:

$other_value = '12345';
session_id($other_value);
session_start();

这篇关于如何在REST客户端应用程序中使用PHP会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆