简体   繁体   中英

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. When print_r session I get empty session for location_id (user session is fine!)

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)

$location_id = $_GET['location_id'];

echo $location_id;

Maybe this can help:

  • you are using $location_id = $_GET['location_id']; (GET method), but in your JS you create a form with a <form method='POST' (POST method).

Isn't $location_id always empty because of this? Maybe that's why nothing changes in your $_SESSION .

Where are you updating your $_SESSION data? (it is not shown in the code). Can you change it to: $_POST['location_id'] and retry?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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