【发布时间】:2023-03-31 04:43:01
【问题描述】:
我的 php SESSION 变量有问题 我的身份验证系统在我的 xampp 服务器上运行良好,但自从我移至 bluehost 后我遇到了问题
通常,如果我打开 index.php 之类的页面,它会检查您是否已登录,如果您没有将您发送到登录页面,但这是行不通的
只是为了测试,我尝试回显$_SESSION['username'],结果显示为空白
现在我按照 ALEX 所说的做了,但我得到了这个错误: 无法修改标头信息 - 第 22 行 /home7/blogboua/public_html/blog.php 中的标头已由(输出开始于 /home7/.../public_html/blog.php:4)发送
代码如下:
<?php session_start(); ?>
<html>
<head>
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
/*-----Connect to Database-----*/
include ('connect_database_2.php');
//check if logged in
function isLoggedIn()
{
if(isset($_SESSION['valid']) && $_SESSION['valid'])
return true;
return false;
}
//if the user has not logged in
if(!isLoggedIn())
{
header('Location: login_form.html');
die();
}
/* get username */
$username = $_SESSION['username'];
/*-----Include Navigation------*/
include ('frame.html');
?>
【问题讨论】: