简体   繁体   English

PHP设置PHPSESSID

[英]PHP set PHPSESSID

I am trying to set the PHPSESSID from a value I received from a CURL POST. 我试图根据从CURL POST收到的值设置PHPSESSID。 However, it is not setting when I assign it to the session_id(). 但是,当我将其分配给session_id()时,它没有设置。 The first echo statement is the correct PHPSESSID from the curl post. 第一个echo语句是curl帖子中正确的PHPSESSID。 However, the second echo returns empty. 但是,第二个回显返回空。 Any thoughts? 有什么想法吗?

PHP 的PHP

//set current session id
session_id($sessID[1]);
echo "current SessID: " . session_id();

//start session
session_start();
echo "PHPSESSID: " . $_COOKIE['PHPSESSID'];

PHP's superglobals are populated with data when the script starts up, and then they are NOT touched again by PHP for the life of the script. 在脚本启动时,PHP的超全局变量将填充数据,然后在脚本生命周期内,PHP 不会再次接触它们。 Your new session ID will only show up on the NEXT request, after the new session cookie's had a chance to round-trip through the client's browser. 在新的会话Cookie可以通过客户端的浏览器往返后,您的新会话ID将仅在NEXT请求上显示。

You cannot echo anything before doing session_start() . 您不能在执行session_start()之前回显任何内容 Per the docs: 根据文档:

Note: To use cookie-based sessions, session_start() must be called before outputing anything to the browser. 注意:要使用基于cookie的会话,必须在将任何内容输出到浏览器之前调用session_start()。

http://us3.php.net//manual/en/function.session-start.php http://us3.php.net//manual/en/function.session-start.php

The way you have it now is messing up the cookie. 您现在拥有的方式就是弄乱了cookie。 And you don't want to be messing up the cookies. 而且您不想弄乱cookie。 :) The end result is the client never recognizes a session id cookie. :)最终结果是客户端永远无法识别会话ID cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM