php - 从另一个 PHP 页面获取值

标签 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']); 以便从其他页面获取它,但它不起作用.我该如何解决?

最佳答案

<?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">

关于php - 从另一个 PHP 页面获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074987/

相关文章:

php - PHP MVC 框架的文件夹结构......我这样做对吗?

php - 在自定义 style.css 文件中的一些更改时,它没有显示 wordpress "[...]"中帖子页面的完整内容

php - 如何在 htaccess 中设置 mod_rewrite?

javascript - 向上滚动时如何重置 scrollTop() div 定位?

html - 当旁边的图像被移除时,中间的文本会移动几个像素

html - CSS 在 IE9 中中断

html - 如何传递 GET 参数并仍然使用 # 跳转到我的页面的一部分?

javascript - 客户端如何使用CORS跨域?

php - PDO MySQL 查询中 LIKE 的 GET 值的 bindParam

php - 使用pdo执行存储过程