当我在我的代码中使用session_start()时,我正确地设置会话,当我运行代码并登录时,它会让我登录并且一切正常,但是当我在位于顶部的PHP代码下面添加HTML时页面并刷新(登录时)它将我退出?
我没有HTML的代码
核心档案
ob_start();
session_start();
function loggedin() {
if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
require 'connect.inc.php';
require 'core.php';
include 'main_login.inc.php';
if (loggedin()) {
$dir = $user_name;
if($handle = @opendir($dir)) {
if($handle2 = @opendir($dir.'/docs')){
//If Logged In And Users File Exists: Load Page
}
} else {
// If Users File Does Not Exist: Create User File
@mkdir($user_name, 0755, true);
// Create Docs
@mkdir($user_name.'/docs', 0755, true);
}
} else {
// If User Is Not Logged: Redirect To Jamie Co Home
@header('Location: http://www.jamieco.ca');
}
?>
我的HTML代码(非工作代码)
<?php
require_once 'connect.inc.php';
require_once 'core.php';
include 'main_login.inc.php';
if (loggedin()) {
$dir = $user_name;
if($handle = @opendir($dir)) {
if($handle2 = @opendir($dir.'/docs')){
//If Logged In And Users File Exists: Load Page
}
} else {
// If Users File Does Not Exist: Create User File
@mkdir($user_name, 0755, true);
// Create Docs
@mkdir($user_name.'/docs', 0755, true);
}
} else {
// If User Is Not Logged: Redirect To Jamie Co Home
@header('Location: #');
}
?>
<!DOCTYPE html>
<html>
<body>
<header>
<nav>
<ul>
<li><a href = "index.html">Home</a></li>
<li><a href = "clients.html">Clients</a></li>
<li><a href = "login.html">Sign In</a></li>
<li><a href = "contact.html">Contact</a></li>
</ul>
</nav>
</header>
<div id = "clear" />
<div id = "big_wrapper">
<div id = "wrapper">
<br><br>
<!-- Logged In Stuff Goes Here -->
<div id = "user_options">
<ul>
<li><?php echo 'Welcome, '.$first_name.' '.$last_name.'<br><br>'; ?></li>
<li><a href = "logout.php">Logout</a></li>
</ul>
</div>
<?php echo 'Welcome Back '.$first_name; ?>
<br><br>
<table border = "1" cellspacing = "5" id = "files">
<tr><td colspan = "7">File Handling</td></tr>
<tr>
<td>File Name:</td>
<td>File Size:</td>
<td>File Type:</td>
<td>Security Level:</td>
<td colspan = "3">Actions:</td>
</tr>
<?php
$dir = $user_name.'/docs/';
if($handle = @opendir($dir)) {
while($file = @readdir($handle)) {
if($file!='.'&&$file!='..') {
echo '<tr><td><a href = "'.$user_name.'/'.$file.'">'.$file.'</a></td>';
$name = $dir.$file;
$size = filesize($dir.$file);
$type = substr($name, strrpos($name, '.')+1);
echo '<td>'.$size.' Bytes'.'</td>';
echo '<td>'.$type.'</td>';
echo '<td>'.$file_grade.'</td>';
echo '<td><a href = "'.$dir.$file.'">'.'Download'.'</a></td>';
echo '<td><a href = "#">'.'Rename'.'</a></td>';
echo '<td><a href = "#">'.'Delete'.'</a></td>';
}
}
}
?>
</tr>
</table>
<br><br>
<!-- Stuff Here -->
<br><br>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
解决了问题。我将会话更改为令牌,不知道为什么会这样,但确实如此!