从PHP到Javascript,再次进入PHP并设置会话

从PHP到Javascript,再次进入PHP并设置会话,javascript,php,session,Javascript,Php,Session,我正在努力解决我遇到的这个问题。问题是,当有人想要登录到管理面板时,我使用此代码: <script> function myFunction() { //alert('you can type now, end with enter'); $("#test").focus(); } $(document).ready(function() { $("form").submit(function(e) {

我正在努力解决我遇到的这个问题。问题是,当有人想要登录到管理面板时,我使用此代码:

 <script>
    function myFunction() {
       //alert('you can type now, end with enter');
       $("#test").focus();
    }
    $(document).ready(function() {
        $("form").submit(function(e) {
            e.preventDefault();
           // alert($("#test").val());

           var email = $("#test").val();

           if(email==''){

 // alert("Error.");
 sweetAlert("Oops...", "Error!", "error");

} else {
$.post("sess.php",{ code1: code},
      function(data) {
     // alert(data);
     // swal(data);
     if((data)=="1") {

      swal("Welcome!", "Please wait!", "success")
     } else {

        sweetAlert("Oops...", "Something went wrong.", "error");

     }
      $('#form')[0].reset(); //To reset form fields
      });

    }



        });
    });

    </script>

我的问题是,如何使用javascript将通过sess.php为用户设置的会话返回到index.php,以便我可以在index.php中设置会话,而不是在sess.php中设置会话?

为什么要将会话传递到javascript?我的意思是,如果您在sess.php上设置了会话服务器端,您甚至已经在index.php中设置了它(会话在整个…会话期间存在:-),因此当sess.php返回验证正确时,您的javascript应该将页面移动到index.php,如下所示:

window.location.href = 'index.php';
在index.php中,如果打印会话print_r($_session),您应该会看到以前在sess.php中设置的值


如果index.php中的$_会话为空,则在使用SESSION_start()读取$_会话之前,可能必须先启动会话

太好了,请选择我的答案;-)
  $_SESSION['sess_id'] = mysql_result($result, 0, 'id');
      $_SESSION['sess_user'] = $username;
window.location.href = 'index.php';