简体   繁体   English

通过管理员在PHP表单中选择的内容来更改其他用户的页面

[英]Change a page for other users by what a admin selects in a form in PHP

I am stuck with a bit of a problem. 我陷入了一个问题。

I have to build an application that shows everyone that visits the webserver a message wich sais if there is maintenance or a failure on the server. 我必须构建一个应用程序,以向访问网络服务器的每个人显示一条消息,表示服务器是否维护或出现故障。

Wich of the 2 messages gets shown to the user depends on what the admin sets it to. 向用户显示的2条消息中的一部分取决于管理员将其设置为什么。 This is done by clicking one of two buttons on the admin page. 通过单击管理页面上的两个按钮之一来完成此操作。

I got it working to the point where if I click one of the two buttons on the admin page it redirects me to the index page and shows the right text. 我得到的结果是,如果我单击管理页面上的两个按钮之一,它将重定向到索引页面并显示正确的文本。

My problem is that the choice I made is a one time thing and will not be saved. 我的问题是我所做的选择是一次性的,不会被保存。 Meaning that if anyone else visits the site he/she gets to see an empty index page. 这意味着如果其他人访问该站点,他/她将看到一个空的索引页面。

I am not allowed to use a database to store the choice i made, so I will have to store the variable somewhere else. 我不允许使用数据库存储所做的选择,因此我将不得不将变量存储在其他位置。
But I have no idea how to save a variable without a database. 但是我不知道如何在没有数据库的情况下保存变量。

My code goes something like this: 我的代码是这样的:

Index.php: Index.php:

if(!session_id()) session_start();

$filename = $_SESSION['filename'];

 $page = $_POST['sb'];
 // // echo $page;
 //
 if($page == 'Maintenance')
 {
      require './pages/index.html';
 }
 elseif($page == 'Failure')
 {
      require './pages/fail.html';
 }

Admin.php: Admin.php:

 if(!session_id()) session_start();
 //include("global.php");
 $_SESSION['filename'] = $page;

 require './functions.php';

 $page = $_POST['sb'];
 change();

Functions.php: Functions.php:

   if(!session_id()) session_start();
    $filename = "test";
    if(!isset($_SESSION['filename'])) {
        $_SESSION['filename'] = $filename;
    }
         echo '<div class="switch">' .
                   '<form method="POST" action="../index.php">' .
                   '<input class="button" type="submit" name="sb" value="Maintenance">' .


          '<input class="button" type="submit" name="sb" value="Failure">' .
           '</form>' .
           '</div>';
}

I would recommend using a txt file as a place to store your data and retrieve it in the index file to display the correct page. 我建议使用txt文件作为存储数据的地方,并在索引文件中检索它以显示正确的页面。

Posting "sb" to txt file on server: 将“ sb”发布到服务器上的txt文件:

<?php
if($_POST['sb'] != ""){
$file = fopen('sbstore.txt', 'w');
fwrite($file, $_POST['sb']);
fclose($file);
}
?>

Retrieving data from txt file on server: 从服务器上的txt文件中检索数据:

<?php
if (filesize('sbstore.txt') != 0){
$txt_file = file_get_contents('sbstore.txt');
$sb = $txt_file;
} else {
$sb = "Default";
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有一种方法可以更改通过使用表单从MYSQL数据库中选择PHP页面的位置? - Is there a way I can change where a PHP page selects from a MYSQL database by using a form? 如何在 wp-admin/users.php 页面添加/删除角色时触发“profile_update”挂钩? (或在这种情况下使用什么其他钩子) - how to fire 'profile_update' hook on adding/removing roles from wp-admin/users.php page? (or what other hook to use in this case) 管理员/用户的登录表单和访问页面PHP - Login form and accessing pages for admin/users PHP 如何防止3位管理员以外的其他用户访问php中的网页? - How to prevent other users other than 3 admin to access a webpage in php? 如何在单个登录表单laravel中将用户重定向到用户页面和管理员到管理页面 - How to redirect a user to users page and admin to admin page in single login form laravel PHP / HTML:使用单选按钮通过管理页面激活用户 - PHP/HTML: activate users through admin page using radio button 从其他页面更改其他页面上的文本 php - Change text on a other page from a other page php 表单发布其他页面使用 php 出错 - Form posting other page getting error with php Fancybox将表单数据发送到其他php页面 - Fancybox sends form data to other php page php表单重定向到其他页面并接收值 - php form redirection to other page and receiving the values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM