I have 3 page, and pass value using $_POST
method. The reason not using $_GET
method is I don't want user go to the url and change the value and able to pass value. From the beginning for t2 and t3 page:
- t2 and t3 will check
if(isset($_POST))
then save to the session. - When t3.php user click on back button, t3 not passing
$_POST
data and read session
It is able to work when passing data from t1 to t2 and t2 to t3, but when click on back button from t3 to t2, the browser show "Confirm Form Resubmission"
. How can I make the page read the session data instead of the $_POST
value when user hit the back button?
t1.php
<html>
<body>
<form id="b">
value1: <input type="text" name="value1" id="value1">
value2: <input type="text" name="value2" id="value2">
<input type="button" onclick ="test()" value="test">
</form>
</body>
</html>
<script type="text/javascript">
function test(){
document.getElementById("b").method = "post";
document.getElementById("b").action = "t2.php";
document.getElementById("value1").value = "asd";
document.getElementById("value2").value = "zxc";
document.getElementById('b').submit();
}
</script>
t2.php
<?php
session_start();
if(isset($_POST)){
unset($_SESSION['t2']);
$_SESSION['t2']=$_POST;
}else if(isset($_SESSION['t2'])){
}else{
header("Location: http://localhost/my_project/t1.php");
}
?>
<html>
<body>
value1<?php echo $_SESSION['t2']["value1"]; ?>!<br>
value2 <?php echo $_SESSION['t2']["value2"]; ?>.
<form id="b">
value1: <input type="text" name="value1" id="value1">
value2: <input type="text" name="value2" id="value12">
<input type="button" onclick ="test()" value="test">
</form>
</body>
</html>
<script type="text/javascript">
function test(){
document.getElementById("b").method = "post";
document.getElementById("b").action = "t3.php";
document.getElementById("value1").value = "qwe";
document.getElementById("value2").value = "rty";
document.getElementById('b').submit();
}
</script>
t3.php
<?php
session_start();
if(isset($_POST)){
unset($_SESSION['t3']);
$_SESSION['t3']=$_POST;
}else if(isset($_SESSION['t3'])){
}else{
header("Location: http://localhost/my_project/t1.php");
}
?>
<html>
<body>
value1<?php echo $_SESSION['t3']["value1"]; ?>!<br>
value2 <?php echo $_SESSION['t3']["value2"]; ?>.
</body>
</html>