Window. location. href: The session becomes invalid after the jump.

Source: Internet
Author: User
Window. location. href after the jump, the session becomes invalid in a php call window. location. href after the jump, the session becomes invalid on the page after the jump. how can this problem be solved?


Reply to discussion (solution)

Where to jump?

Your code

Where to jump?

Your code

$url = "main.php";window.location.href='$url';


That's it.

No session is set in your code.
Why is the session lost?

No session is set in your code.
Why is the session lost?



There are some settings. before the code, I thought you should see how it jumps.
That is, set session = ['check'] = true.
Then the true value cannot be read when it is followed.

Isn't that wrong ?!
Session = ['check'] = true
Is this a Martian style?

Isn't that wrong ?!
Session = ['check'] = true
Is this a Martian style?


The error code is correct. I can read the things in the session on the page that is not redirected.
However, the session cannot be read on the page to be jumped.

I don't want to talk to you anymore.
The premise of the discussion is sincerity, and the foundation is equality.

I don't want to talk to you anymore.
The premise of the discussion is sincerity, and the foundation is equality.


When window. location. href is used in php to jump to a webpage, the redirected webpage and the session of the original webpage cannot be shared.
This is the nature of the session. I found this problem elsewhere, but there is no clear solution, not to say that my code has a problem or it is not a problem of code, I think I have already explained my problem. when I jump to a webpage, the session of the original webpage cannot be read from the webpage after the jump. how can I solve this problem.
In addition, I think I am sincere enough, and I have already told you everything I know.

The correct statement of Session is:
Session_start ();
$ _ SESSION ['favcolor'] = 'green ';
$ _ SESSION ['Animal '] = 'cat ';
$ _ SESSION ['Time'] = time ();
This is similar.
Different domains may change the session. The following is an example of jsp. you can understand it at a glance. although you use php, the idea is the focus.

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
<%
String JSESSIONID = request. getSession (). getId (); // Obtain the current JSESSIONID (generated by access from the primary or secondary domains)

Cookie cookie = new Cookie ("JSESSIONID", JSESSIONID );
Cookie. setDomain (".test.com"); // The key is to set the cookie to the primary domain name for access, so that the cookie value can be obtained between different domains, so as to ensure session consistency
Response. addCookie (cookie); // return the cookie to the client

Request. getRequestDispatcher ("indes. jsp"). forward (request, response );

%>
Reference Page
Http://www.cnblogs.com/nicholas_f/archive/2010/11/05/1869811.html

The correct statement of Session is:
Session_start ();
$ _ SESSION ['favcolor'] = 'green ';
$ _ SESSION ['Animal '] = 'cat ';
$ _ SESSION ['Time'] = time ();
This is similar.
Different domains may change the session. The following is an example of jsp. you can understand it at a glance. although you use php, the idea is the focus.

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
<%
String JSESSIONID = request. getSession (). getId (); // Obtain the current JSESSIONID (generated by access from the primary or secondary domains)

Cookie cookie = new Cookie ("JSESSIONID", JSESSIONID );
Cookie. setDomain (".test.com"); // The key is to set the cookie to the primary domain name for access, so that the cookie value can be obtained between different domains, so as to ensure session consistency
Response. addCookie (cookie); // return the cookie to the client

Request. getRequestDispatcher ("indes. jsp"). forward (request, response );

%>
Reference Page
Http://www.cnblogs.com/nicholas_f/archive/2010/11/05/1869811.html


I understand you, but I also want to ask how window. location. href redirects.

Your attitude is sincere, but the information you and I have (you don't want to provide) is not right.
Your code is faulty, so it may be wrong!

   
Session_target.
      
The truth is there. let's say no!

Your attitude is sincere, but the information you and I have (you don't want to provide) is not right.
Your code is faulty, so it may be wrong!

      
Session_target.
          
The truth is there. let's say no!
Index. php:

     

Main. php:
     




This is similar to yours, but the output is null.


Your attitude is sincere, but the information you and I have (you don't want to provide) is not right.
Your code is faulty, so it may be wrong!

         
Session_target.
              
The truth is there. let's say no!
Index. php:

       

Main. php:
       




This is similar to yours, but the output is null.


If some codes are reversed, the values are assigned first.

Your attitude is sincere, but the information you and I have (you don't want to provide) is not right.
Your code is faulty, so it may be wrong!

          
Session_target.
              
The truth is there. let's say no!




Then I changed it according to yours.
Index. php
         


Session_target.php:
         


The output is empty.

This is yours! I am clearly wrong, but I still don't recognize it
$ _ Session ["check"] = true;
Ying writing
$ _ SESSION ["check"] = true;

Php variable names are case sensitive

This is yours! I am clearly wrong, but I still don't recognize it
$ _ Session ["check"] = true;
Ying writing
$ _ SESSION ["check"] = true;

Php variable names are case sensitive



Oh, oh, oh, sorry for your delay. thank you very much!

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.