[英]How to turn on/off a php file while in admin page?
Using the Admin page, I want to toggle on/off or enable/disable a php file and I'm using sessions but the session stops as I close the browser. 使用“管理”页面,我想打开/关闭或启用/禁用php文件,并且正在使用会话,但是在关闭浏览器时会话停止。 I want to keep the session active even if I close the browser.
即使关闭浏览器,我也希望保持会话活动状态。 Am I using the right code?
我使用的代码正确吗? I think it's not session...?
我认为这不是会议...?
<form method="post" action="">
<td colspan="2" bgcolor="#FFFFFF" valign="left">
<strong>APPLICATION FORM:
<select name="switch" id="switch" align="center" valign="center">
<option></option>
<option>ON</option>
<option>OFF</option>
</strong>
</SELECT>
<input type="submit" name="submit" value="SUBMIT">
<?php
if(isset($_POST['submit'])){
include('config.php');
$switch=($_POST['switch']);
if ($_POST['switch'] == "ON"){
$_SESSION['switch'] = $switch;
echo "<script language='javascript' type='text/javascript'>";
echo "alert('Application form ACTIVATED!');";
echo "</script>";
echo 'ON';
}
if ($_POST['switch'] == "OFF"){
echo "<script language='javascript' type='text/javascript'>";
echo "alert('Application form DEACTIVATED!');";
echo "</script>";
echo 'OFF';
session_destroy();
header('location.href=index.php');
}
}
?>
</td>
</form>
<?php
session_start();
?>
<?php
$con = mysql_connect('localhost','root','');
if (!$con) {
die('Could not connect:'.mysql_error());
}
mysql_select_db ('psp',$con);
if (!isset($_SESSION['switch'])){
header('location:index.php');
}
?>
You can turn off/on a page using database or file in saving the settings.. 您可以在保存设置时使用数据库或文件关闭/打开页面。
yes, sessions can be used to disable/enable php files, but it would reset on browser exit. 是的,可以使用会话禁用/启用php文件,但是它将在浏览器退出时重置。 While cookies can be useful, the settings will reset when you clear browser cookies or if the cookies expires..
尽管cookie可能有用,但是当您清除浏览器cookie或cookie过期时,设置将重置。
the best approach would be using database or a file in saving the settings.. 最好的方法是使用数据库或文件保存设置。
so, you can create a table in your database with columns: 因此,您可以在数据库中创建带有列的表:
select * from file_settings;
+-------+-------------+-----------+
| id | filename | status |
+-------+-------------+-----------+
| 0 | file.php | ON |
+-------+-------------+-----------+
then on your file.php
: 然后在您的
file.php
:
<?php
/* code for getting the columns in file_settings:
lets make a shortcut, just query the database and
it will output every row in the table as $row
*/
if("file.php" == $row['filename'] && $row['status'] != "ON") {
header('the_redirect_page.php');
}
// if false then proceed to page
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.