我最近遇到了我的代码问题: 下面是我的测试代码 我有2个文件php:index.php& shop.php - 选择' shopid' (例如:shop01)来自index.php并作为POST方法发送到shop.php - 在shop.php:我检查邮政请求是否有shopid - >将shopid设为$ _SESSION [' shopid'] - 现在我回到index.php并选择新店(shop02) - 在tab shop01中我按下刷新按钮=> shopid现在是shop02
如何处理我重新加载时打开的每个标签浏览器的shopid。 示例:Tab1为shop01,Tab2为shop02,重新加载时Tab01 shop01不会更改。
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>