简体   繁体   English

两页之间的php会话

[英]php session between two pages

My goal is to open a new session (there is a login system with a session for the user ) when the user clicks play the location_id , then he is redirected to the next page and there he would select data from the db.我的目标是当用户点击播放location_id时打开一个新会话(有一个带有用户会话的登录系统),然后他被重定向到下一页,他将从数据库中选择数据。 When print_r session I get empty session for location_id (user session is fine!)print_r会话时,我得到location_id空会话(用户会话很好!)

here the user select a point用户在这里选择一个点

$location_id = $_GET['location_id'];

echo $location_id;


        var i ; var confirmed = 0;
        for (i = 0; i < locations.length; i++) {
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                map: map,
                icon :   locations[i][4] === '1' ?  red_icon  : purple_icon,
                html: "<div id='window_loc'>\n" +
                "<form method='POST' action='question.php'>\n" +
                "<table class=\"map1\">\n" +
                "<tr>\n" +
                "<td><input type='hidden'  id='manual_description'/>"+locations[i][3]+"</td></tr>\n" +
                "<tr>\n" +
                "<td><textarea disabled  id='question' placeholder='Question'>"+locations[i][5]+"</textarea></td></tr>\n" +
                "<tr>\n" +
                "<td><input type='hidden' name='location_id' id='location_id' value="+locations[i][0]+" /></td></tr>\n" +
                "<td><input id='button1' name='play' type='submit' value='play'/> </td></tr>\n" +
                "</table>\n" +
                "</form>\n" +
                "</div>"
            });


            google.maps.event.addListener(marker, 'click', (function(marker, i) {
                return function() {
                    infowindow = new google.maps.InfoWindow();
                    confirmed =  locations[i][4] === '1' ?  'checked'  :  0;
                    $("#confirmed").prop(confirmed,locations[i][4]);
                    $("#location_id").val(locations[i][0]);
                    $("#description").val(locations[i][3]);
                    $("#form").show();
                    infowindow.setContent(marker.html);
                    infowindow.open(map, marker);
                }
            })(marker, i));
        }




I've added this to the page where the user is redirected but the session is empty ( there is a session_start and it works - print_r shows user id)我已将此添加到用户被重定向但会话为空的页面(有一个 session_start 并且它可以工作 - print_r显示用户 ID)

$location_id = $_GET['location_id'];

echo $location_id;

Maybe this can help:也许这可以帮助:

  • you are using $location_id = $_GET['location_id'];您正在使用$location_id = $_GET['location_id']; (GET method), but in your JS you create a form with a <form method='POST' (POST method). (GET 方法),但是在您的 JS 中,您使用<form method='POST' (POST 方法)创建了一个表单。

Isn't $location_id always empty because of this?因为这个, $location_id不是总是空的吗? Maybe that's why nothing changes in your $_SESSION .也许这就是为什么你的$_SESSION没有任何变化。

Where are you updating your $_SESSION data?你在哪里更新你的$_SESSION数据? (it is not shown in the code). (它没有显示在代码中)。 Can you change it to: $_POST['location_id'] and retry?您可以将其更改为: $_POST['location_id'] _ $_POST['location_id']试吗?

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

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