Are you there? PHP cannot understand the modification of session and cookie!

Source: Internet
Author: User
Tags send cookies set cookie
Are you there? PHP cannot understand the modification of session and cookie! Check whether SESSIONID has been modified for the following two functions. Why can't I get the correct id? Each time the browser generates a fixed id, the id I get is changing.
/*** Session management function ** @ param string | array $ name if the session name is an array, the session is set * @ param mixed $ value session value * @ return mixed */function session ($ name, $ value = '') {$ prefix = C ('session _ prefix'); if (is_array ($ name )) {// session initialization calls if (isset ($ name ['prefix']) C ('session _ prefix', $ name ['prefix']) before session_start; if (C ('Var _ SESSION_ID ') & isset ($ _ REQUEST [C ('Var _ SESSION_ID')]) {session_id ($ _ REQUEST [C ('Var _ SESSION_ID ')]);} elseif (isset ($ name ['id']) {session_id ($ name ['id']);} ini_set ('session. auto_start ', 0); if (isset ($ name ['name']) session_name ($ name ['name']); if (isset ($ name ['path']) session_save_path ($ name ['path']); if (isset ($ name ['domain']) ini_set ('session. cookie_domain ', $ name ['domain']); if (isset ($ name ['expire ']) ini_set ('session. gc_maxlifetime', $ name ['expire ']); if (isset ($ name ['us E_trans_sid ']) ini_set ('session. use_trans_sid', $ name ['use _ trans_sid ']? 1:0); if (isset ($ name ['use _ cookies ']) ini_set ('session. use_cookies', $ name ['use _ cookies ']? 1-0); if (isset ($ name ['cache _ limiter ']) session_cache_limiter ($ name ['cache _ limiter']); if (isset ($ name ['cache _ expire ']) session_cache_expire ($ name ['cache _ expire']); if (isset ($ name ['type']) C ('session _ type', $ name ['type']); if (C ('session _ type') {// Read SESSION driver $ class = 'session '. ucwords (strtolower (C ('session _ type'); // check the driver class if (require_cache (EXTEND_PATH. 'driver/Session /'. $ class. '. class. php ')){ $ Hander = new $ class (); $ hander-> execute ();} else {// The class does not define throw_exception (L ('_ CLASS_NOT_EXIST _'). ':'. $ class) ;}}// start session if (C ('session _ AUTO_START ') session_start () ;} elseif (''===$ value) {if (0 === strpos ($ name, '[') {// session operation if ('[pause]' = $ name) {// pause session session_write_close ();} elseif ('[start]' ==$ name) {// start session session_start ();} elseif ('[destroy]' = $ name) {// destroy sessio N $ _ SESSION = array (); session_unset (); session_destroy ();} elseif ('[regenerate]' = $ name) {// regenerate id session_regenerate_id () ;}} elseif (0 === strpos ($ name ,'? ') {// Check session $ name = substr ($ name, 1); if (strpos ($ name ,'. ') {// supports array list ($ name1, $ name2) = explode ('. ', $ name); return $ prefix? Isset ($ _ SESSION [$ prefix] [$ name1] [$ name2]): isset ($ _ SESSION [$ name1] [$ name2]);} else {return $ prefix? Isset ($ _ SESSION [$ prefix] [$ name]): isset ($ _ SESSION [$ name]) ;}} elseif (is_null ($ name )) {// clear session if ($ prefix) {unset ($ _ SESSION [$ prefix]);} else {$ _ SESSION = array () ;}} elseif ($ prefix) {// Obtain the session if (strpos ($ name ,'. ') {list ($ name1, $ name2) = explode ('. ', $ name); return isset ($ _ SESSION [$ prefix] [$ name1] [$ name2])? $ _ SESSION [$ prefix] [$ name1] [$ name2]: null;} else {return isset ($ _ SESSION [$ prefix] [$ name])? $ _ SESSION [$ prefix] [$ name]: null ;}} else {if (strpos ($ name ,'. ') {list ($ name1, $ name2) = explode ('. ', $ name); return isset ($ _ SESSION [$ name1] [$ name2])? $ _ SESSION [$ name1] [$ name2]: null;} else {return isset ($ _ SESSION [$ name])? $ _ SESSION [$ name]: null ;}} elseif (is_null ($ value) {// delete session if ($ prefix) {unset ($ _ SESSION [$ prefix] [$ name]);} else {unset ($ _ SESSION [$ name]);} else {// Set session if ($ prefix) {if (! Is_array ($ _ SESSION [$ prefix]) {$ _ SESSION [$ prefix] = array ();} $ _ SESSION [$ prefix] [$ name] = $ value;} else {$ _ SESSION [$ name] = $ value ;}}} /*** set, retrieve, and delete cookies * @ param string $ name Cookie name * @ param mixed $ value cookie value * @ param mixed $ options cookie parameter * @ return mixed */ function cookie ($ name, $ value = '', $ option = null) {// Default $ config = array ('prefix' => C ('cookie _ prefix '), // cookie name prefix 'expire '=> C ('cookie _ EXPIRE'), // COOKIE storage time 'path' => C ('cookie _ path '), // cookie storage path 'domain '=> C ('cookie _ domain'), // COOKIE valid DOMAIN name); // parameter settings (will overwrite? Set) if (! Is_null ($ option) {if (is_numeric ($ option) $ option = array ('expire '=> $ option); elseif (is_string ($ option )) parse_str ($ option, $ option); $ config = array_merge ($ config, array_change_key_case ($ option ));} // clear all the cookies with the specified prefix if (is_null ($ name) {if (empty ($ _ cookie) return; // The COOKIE prefix to be deleted, if this parameter is not specified, the specified prefix $ prefix = empty ($ value) set in config will be deleted )? $ Config ['prefix']: $ value; if (! Empty ($ prefix) {// if the prefix is an empty string, the foreach ($ _ COOKIE as $ key => $ val) is returned without processing) {if (0 === stripos ($ key, $ prefix) {setcookie ($ key, '', time ()-3600, $ config ['path'], $ config ['domain ']); unset ($ _ COOKIE [$ key]) ;}}return ;}$ name = $ config ['prefix']. $ name; if (''===$ value) {if (isset ($ _ COOKIE [$ name]) {$ value =$ _ COOKIE [$ name]; if (0 === strpos ($ value, 'think: ') {$ value = substr ($ value, 6); return Rray_map ('urldecodecode', json_decode (MAGIC_QUOTES_GPC? Stripslashes ($ value): $ value, true);} else {return $ value ;}} else {return null ;}} else {if (is_null ($ value )) {setcookie ($ name, '', time ()-3600, $ config ['path'], $ config ['domain ']); unset ($ _ COOKIE [$ name]); // delete specified cookie} else {// Set cookie if (is_array ($ value) {$ value = 'think :'. json_encode (array_map ('urlencode', $ value) ;}$ expire =! Empty ($ config ['expire '])? Time () + intval ($ config ['expire ']): 0; setcookie ($ name, $ value, $ expire, $ config ['path'], $ config ['domain ']); $ _ COOKIE [$ name] = $ value ;}}}


Reply to discussion (solution)

Terrible

Are you talking about me ......

Lots of if else


Are you talking about me ......

I mean, the person who writes this code is so funny.

A bunch of if else phpthink



Are you talking about me ......

I mean, the person who wrote this code is too funny to write phpthink.

Thinkphp, phpthink from there

Thinkphp, the phpthink from there. I am right here to help you.

Isn't this a built-in function of thinkphp?
What do you want to do?

Isn't this a built-in function of thinkphp?
What do you want to do? The problem still persists. I suspect that it is not a client program, but the internal mechanism of thinkPHP.

Can you access it in a browser?

Can you access it in a browser? Yes.

It means there is something wrong with your client.

It indicates that your client has a problem, but the php backend has modified the session and cookie.

Whether or not the backend has modified the session and cookie
As long as the browser can be normally accessed, it means that the system works normally.
This proves that your client has a problem: the cookie cannot be obtained correctly.

Is the problem clearly described?

Whether or not the backend has modified the session and cookie
As long as the browser can be normally accessed, it means that the system works normally.
It also confirms that your client has a problem: the session generated by the browser is not fixed when the cookie is not obtained correctly! However, I have fixed it here. I checked it and said it was a thinkPHP problem. the configuration file php. ini was modified, and it was invalid. so I think it was a php backend problem.

Is the problem clearly described? I don't understand where it is.

The session is generated by the server. as long as the browser does not leave the website, the session id will not change.


Is the problem clearly described? I don't understand where it is.
Thinkphp sessions are also called based on the php session method.

The session is generated by the server. as long as the browser does not leave the website, the session id will not change.

session_id();
Isn't this a function for modifying sessionid?



Is the problem clearly described? I don't understand where it is.
Thinkphp sessions are also called based on the php session method. Suspect that he modified the session

You 'd better read it with another post from the landlord!
The landlord wrote a simulated login program in C #, and the login status cannot be maintained.
Therefore, thinkphp is suspected to be a problem.



Is the problem clearly described? I don't understand where it is.
Thinkphp sessions are also called based on the php session method.

Whether or not sessionid is changed
Your client only needs to be able to correctly read and send cookies.

Your client is onlySimulationBrowser behavior

Your client is onlySimulationBrowser behavior! But no one answered questions in Section C ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.