Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包含的PHP+MySQL登录_Php_Html_Mysql_Login_Include - Fatal编程技术网

包含的PHP+MySQL登录

包含的PHP+MySQL登录,php,html,mysql,login,include,Php,Html,Mysql,Login,Include,我正在为我使用PHP和MySQL创建的网站创建一个登录系统。数据库结束我已经做了,一切都在工作 这是我的问题。我的网站与includes一起工作。基本上我有index.php,这是我的模板,我使用id将页面调用到页面主体中。ie:index.php?id=about、index.php?id=admin等 根据登录教程的指导,我的admin页面admin.php上面有这个 <?php session_start(); include_once 'dbconnect.php'; if(!i

我正在为我使用PHP和MySQL创建的网站创建一个登录系统。数据库结束我已经做了,一切都在工作

这是我的问题。我的网站与includes一起工作。基本上我有index.php,这是我的模板,我使用id将页面调用到页面主体中。ie:index.php?id=about、index.php?id=admin等

根据登录教程的指导,我的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是为了使用我的模板,因此出现以下错误:

警告:会话启动[函数.会话启动]:无法发送会话 缓存限制器-标头已发送,输出在开始 /home/content/08/10038808/html/sites/danintra/index.php:28英寸 /第2行的home/content/08/10038808/html/sites/danintra/admin.php

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

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

index.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>
尝试启动会话;在index.php的最顶端,尝试启动会话;在index.php的最顶端尝试以下操作:-

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

if(!isset($_SESSION['user']))
{
 //header("Location: index.php");
 echo "<scrip>window.location='index.php'</script>";
}
$res=mysql_query("SELECT * FROM danusers WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>
试试这个:-

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

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

我不知道index.php中做了什么。但是,在包含admin.php等之前,必须先打印一些内容。你可以试着用ob_start来缓冲它。 只需将其添加到顶部的index.php中

index.php

<?php ob_start();

我确信它正在工作

我不知道index.php中做了什么。但是,在包含admin.php等之前,必须先打印一些内容。你可以试着用ob_start来缓冲它。 只需将其添加到顶部的index.php中

index.php

<?php ob_start();

我确信它正在工作

用谷歌搜索你的PHP警告让我想到了这一点,如果我认为你已经开始了会话_在其他地方启动index.PHP?那么你在index.PHP页面中包括admin.PHP页面,基于类似index.PHP?id=admin的url,对吗?如果是这样的话,那么从admin.php页面删除这一行session_start,并将其放在index.php页面的最顶端,就在我最初的想法是@chay22这样的打开php标记之后,但在我的索引上没有session_start。php@RajdeepPaul这样就消除了错误,但即使没有日志记录,也可以查看页面内容in@Brooke你确定已经没有了吗?把ob_start放在session_start之前怎么样?谷歌搜索你的PHP警告让我想到了这一点,如果我认为你已经在其他地方启动了session_start index.PHP?那么你在index.PHP页面中包含了admin.PHP页面,基于像index.PHP?id=admin这样的url,对吗?如果是这样的话,那么从admin.php页面删除这一行session_start,并将其放在index.php页面的最顶端,就在我最初的想法是@chay22这样的打开php标记之后,但在我的索引上没有session_start。php@RajdeepPaul这样就消除了错误,但即使没有日志记录,也可以查看页面内容in@Brooke你确定已经没有了吗?将ob_start放在session_start之前如何?这样可以删除错误,但即使不登录也可以查看页面内容。已解决!我得到了浏览器缓存,需要先清除才能实现更改。谢谢是的,我们必须注意缓存。通常,我只对JS和CSS文件进行缓存以消除错误,但即使不登录页面内容也可以查看。已解决!我得到了浏览器缓存,需要先清除才能实现更改。谢谢是的,我们必须注意缓存。通常,我只对JS和CSS文件进行缓存