使用Admin页面,我想打开/关闭或启用/禁用php文件,我正在使用会话,但会话在我关闭浏览器时停止。即使关闭浏览器,我也希望会话保持活动状态。我使用正确的代码吗?我认为这不是会议......?
<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');
}
?>
答案 0 :(得分:2)
您可以在保存设置时使用数据库或文件关闭/打开页面。
是的,会话可用于禁用/启用php文件,但它会在浏览器退出时重置。虽然cookie很有用,但当您清除浏览器cookie或Cookie过期时,设置将重置。
最好的方法是使用数据库或文件保存设置..
因此,您可以使用列创建数据库中的表:
select * from file_settings;
+-------+-------------+-----------+
| id | filename | status |
+-------+-------------+-----------+
| 0 | file.php | ON |
+-------+-------------+-----------+
然后在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
?>