How to read $ _SESSION on IE-11?

I am working on a task trying to submit a form in IE:

1.- When I am on page1.php and click “Submit”, I get a jQuery dialog box popup and then click “Yes, I accept”, it brings me to page2.php and if I click on “back” she brings me back to page1.php

2.- I also have php SESSION called inProgress, which sets the value to 1 when the user goes from page1.php to page2.php. This basically means that while the user clicks the Yes, I accept button only once, the user does not have to pop up to show more (even if the user goes back and forth).

Questions:

a) Somehow, when the user clicks the “Submit” button (on page 1.php), a popup appears and they automatically click on “Yes, I accept”, but then I don’t get a popup, even if I come back, what well. However, I would prefer to click the "Yes, I agree" button.

b) The main problem is that I keep showing the popup, even if I go back and forth when I use IE-11 (I want the popup to show only once).

How can I pop up to show ONLY ONCE after clicking “Yes, I accept” on IE-11, or, in other words, how can I make sure that the session is read on IE-11 correctly? I was thinking about using cookies with javascript, but I don't know how to implement this ... Someone is helping me. Thank you so much for the advanced! Here is my code for page1.php and page2.php

page1.php,

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "submit" id="btnOpenDialog" name = "submit">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#btnOpenDialog").click(function(){
var inProgress = $('#inProgress').val();
if (inProgress !== "1") {
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "Title",
height: 250,
width: 350,
closeOnEscape: false,
buttons: {
  "Yes, I accept": function () {
    $('#homeForm').submit();
    },
    "No, thanks": function () {
      $(this).dialog('close');
    }
  }
  });
  }
 });
});
</script>
</body>
</html>

page2.php

 <html ng-app="store">
 <head>
 <title>Page1</title>
 </head>
 <body>
 <h1>This is Page 2</h1>
 <div id="dialog-confirm"></div>
 <script type="text/javascript">

 function myfunction() {
 window.location.href="page1.php";
 }

 </script>
 <input type="button" id="btnOpenDialog"  onclick = "myfunction()"   value="Back" />

</body>
</html>
+4
source share
2 answers

Do not think that this is not a problem with the browser (we are talking about sessions, that is, only on the server side, on the client you only have a token to indicate what your session is).

, , ( , javascript).

, ​​ localStorage. localStorage cookies ( ), SimpleStorage.js ( github).

- , localStorage ( localStorage ), , , , page2 store :

$('#btnOpenDialog').on('click', function(){
   localStorage.setItem('dialogAccepted', 'true'); //you can string just strings, if you ever need to store comples data use JSON.stringify(variable) so it parsed to json
})

page1, , ( thingy), :

if(localStorage.getItem('dialogAccepted') === 'true'){
  //code to disable the dialog pop up
} 

"" : , . :

$(document).ready(function () {
    var preventedDefaultMet = false;
    $("#btnOpenDialog").on('click', function (event) {
        var inProgress = $('#inProgress').val();
        if (inProgress !== "1") {
            if (!preventedDefaultMet) {//so when the dialog was accepted we can trigger the click event and do not enter an infinite loop of dialogs
                event.preventDefault();//to prevent the browser from making the POST call
            }
            $("#dialog-confirm").dialog({
                resizable: false,
                modal: true,
                title: "Title",
                height: 250,
                width: 350,
                closeOnEscape: false,
                buttons: {
                    "Yes, I accept": function () {
                        preventedDefaultMet = true; // set flag
                        $('#homeForm').trigger('submit');//accepted! just trigger the click! yay!
                    },
                    "No, thanks": function () {
                        $(this).dialog('close');//trigger the click
                    }
                }
            });
        }
    });
});

, , , . , , $_SESSION['inProgress'] = "1"; - , javascript :

<form id="homeForm" name="homeForm" method = "POST">
        <input type = "submit" id="btnOpenDialog" name = "submit">
        <input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
    </form>
<script>
   // when the browser reads this it will store the value PHP printed into the javascript variable
   var someJavaScriptVar = <? echo $_POST ? true : false ;?>;
</script>

, $_SESSION['inProgress'] = "1";, , . if (inProgress !== "1") { if (someJavaScriptVar) {. .

+2

1 . <input type = "submit" id="btnOpenDialog" name = "submit"> , .

:

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "button" id="btnOpenDialog" name = "submit" onclick="yourfunctionABC()">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">

function yourfunctionABC(){
 xxx}

, ? :

if(session_id() == '' || !isset($_SESSION)) {
    session_set_cookie_params(3600, '/', '.example.com');  
    // session isn't started
    session_start();//create unique session for user
}

reset 2- ? , .

, .

+1

All Articles