从另一个PHP页面获取值

时间:2015-06-26 13:50:48

标签: php html get

您好我的页面viewsensordata.php

中有以下表格
...

$refresh = ($_POST['refresh']);

$link_address="viewsensordata.php?view=".$view;
?>
<form method="post" action="<?php echo $link_address;?>">
<select id="refresh" name="refresh">
    <option value="-">Select Seconds</option>
    <option value="1">1 Second</option>
    <option value="2">2 Seconds</option>
    <option value="3">3 Seconds</option>
    <option value="4">4 Seconds</option>
    <option value="5">5 Seconds</option>
    <option value="10">10 Seconds</option>
    <option value="15">15 Seconds</option>
    <option value="30">30 Seconds</option>
    <option value="60">60 Seconds</option>
</select>
<input type="submit" value="Refresh" name="refresh_rate"/>
</form>
<meta http-equiv="Refresh" content="<?php echo $refresh;?>;URL=refreshsensorData.php">
<br />

我希望将$refresh的值提供给另一个名为viewsensordata2.php的页面

viewsensordata2.php我有$refresh = ($_GET['refresh']);以便从其他页面获取它但它不起作用。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

<?php
$link_address="viewsensordata.php?view=".$view;
?>
<form method="post" action="<?php echo $link_address;?>">
<select id="refresh" name="refresh">
    <option value="-">Select Seconds</option>
    <option value="1">1 Second</option>
    <option value="2">2 Seconds</option>
    <option value="3">3 Seconds</option>
    <option value="4">4 Seconds</option>
    <option value="5">5 Seconds</option>
    <option value="10">10 Seconds</option>
    <option value="15">15 Seconds</option>
    <option value="30">30 Seconds</option>
    <option value="60">60 Seconds</option>
</select>
<input type="submit" value="Refresh" name="refresh_rate"/>
</form>

然后在第二页中,您可以像这样刷新它:

<?php
if(isset($_POST) && isset($_POST['refresh'])){
   $sec = $_POST['refresh'];
}
elseif(isset($_GET) && isset($_GET['seconds'])){
   $sec = $_GET['seconds'];
}
else{
   $sec = 10; // your defualt seconds, if it is not set from form or URL
}
?>

<meta http-equiv="Refresh" content="<?php echo $sec ;?> URL=<?php echo $_SERVER['PHP_SELF']; ?>?seconds=$sec">