gpt4 book ai didi

包含的 PHP + MySQL 登录

转载 作者:行者123 更新时间:2023-11-29 04:37:54 24 4
gpt4 key购买 nike

我正在为我使用 PHP 和 MySQL 创建的网站创建登录系统。数据库端我已经完成,一切正常。

这是我的问题。我的网站使用 includes。基本上我有 index.php,这是我的模板,我使用 id 将页面调用到该页面的主体中。 (即:index.php?id=about、index.php?id=admin 等)

按照登录教程的指示,我的管理页面 (admin.php) 将其置于顶部

<?php
session_start();
include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM danusers WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>

但是因为 admin.php 被加载为 index.php?id=admin(为了使用我的模板)我得到这个错误:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/08/10038808/html/sites/danintra/index.php:28) in /home/content/08/10038808/html/sites/danintra/admin.php on line 2

我认为解决此问题的最简单方法是为我的所有管理页面创建另一个模板文件,然后将每个相应的页面包含到该模板文件中,但是有没有一种方法可以在不执行这些额外步骤的情况下执行此操作?

我真的希望有人理解我的问题,如果已经回答了很多很多次,我再次道歉。我真的用尽了搜索关键字来找到我真正要找的东西。

索引.php:

<?php
include 'dbconnect.php';

$sql = mysql_query ("SELECT * FROM `danintra` WHERE id='1'");
$row=mysql_fetch_array($sql);

?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:600' rel='stylesheet' type='text/css'>
<title><?php echo $row['title'];?> | <?php echo $row['subtitle'];?></title>
<style>
body {text-align:center;margin-top:27px;margin-bottom:27px;background-color:#C3C3C3;font-family: 'Open Sans', sans-serif;}
.wrap {width:90%;max-width:1200px;margin:0px auto;background-color:#FFFFFF;}
.header {width:100%;}
.main {width:100%;}
.page {padding:40px;margin-bottom:40px;}
.footer {width:100%;}
.button-add {color:#FFFFFF;background-color:#e2393e;text-transform:uppercase;text-decoration:none;font-weight:bold;padding:15px;float:right;margin-top:10px;margin-bottom:10px;}
.pdf {color:#FFFFFF;background-color:#e2393e;text-transform:uppercase;text-decoration:none;font-weight:bold;width:100px;padding:15px;margin-top:50px;}
</style>
</head>
<body>

<table class="wrap" border=0 cellpadding=0 cellspacing=0>
<tr><td class="header">
<?php include ('header.php'); ?>
</td>
</tr><tr>
<td class="main">
<?php
$id=$_GET['id'];
if (!empty($id)) {
$page = $id. ".php";
if(file_exists("$page")){
include("$page");
}
else {
include("error.php");
}
}
else {
include("home.php");
} ?>
</td>
</tr><tr>
<td class="footer">
<?php include ('footer.php'); ?></td>
</tr>
</table>

</body>
</html>

最佳答案

尝试将 session_start(); 放在 index.php 的最顶部

关于包含的 PHP + MySQL 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36860579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com