0

I have issue with my code recently: Below is my test code I have 2 file php: index.php & shop.php - Select 'shopid' (example: shop01) from index.php and send as POST method to shop.php - In shop.php : i check if has shopid from post request -> set shopid to $_SESSION['shopid'] - Now i back to index.php and select new shop (shop02) - in tab shop01 i press refresh button => shopid now is shop02

How to handle shopid for each tab browser i opened when i reload. Example: Tab1 is shop01, Tab2 is shop02, when reload Tab01 shop01 will not change.

Index.php :

<?php
    session_start();
    $shop = array('shop1','shop2','shop3','shop4');

?>

<html>
<body>
<div id='my-header'>
  <!-- Header content goes here -->
</div>

<div id="my-content">

<form method="POST" action="shop.php" target="_blank">

    <select name="shopid">
    <?php
        foreach($shop as $value){
            echo '<option value="'.$value.'">'.$value.'</option>';
        }


    ?>
    </select>
    <input type="submit" name="send">
</form>
</div>


</body>
</html>

Shop.php:

<?php

    session_start();
    if(isset($_POST['shopid'])){
        $_SESSION['shopid'] = $_POST['shopid'];
    }
    $shopid = $_SESSION['shopid'] ?: 'no shop select';
?>

<!DOCTYPE html>
<html>
<head>
    <title>TEST SHOP ID</title>
</head>
<body>
    <?php  echo  $shopid; ?>
</body>
</html>

0 Answers0