Brooke Brooke - 1 year ago 46
HTML Question

(SOLVED!) PHP + MySQL Login for Includes

I apologize in advanced if this has been answered a billion times. I simply don't know how what keywords to use to find the answer.

I am creating a login system for a website I have created using PHP and MySQL. The database end I have already done and everything is working.

Here is my problem. My website works with includes. Basically I have index.php which is my template and I work off of id's to call the pages into the body of that page. (ie: index.php?id=about, index.php?id=admin, etc.)

My admin page (admin.php) has this on top, as instructed by login tutorials

include_once 'dbconnect.php';

header("Location: index.php");
$res=mysql_query("SELECT * FROM danusers WHERE user_id=".$_SESSION['user']);

But because admin.php is loaded as index.php?id=admin (for the sake of using my template) I get this error:

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

The easiest way I see to solve this is to create another template file for all my admin pages and then include each respective page into that one, but is there a way to do this without those extra steps?

I really hope someone understands my question and once again I apologize if it has been answered many, many times. I literally have run out of search keywords to find what I am truly looking for.

Thanks in advance!



include 'dbconnect.php';

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


<link rel="stylesheet" type="text/css" href="style.css">
<link href='' rel='stylesheet' type='text/css'>
<title><?php echo $row['title'];?> | <?php echo $row['subtitle'];?></title>
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;}

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


Answer Source

Try to put session_start(); at the very top of your index.php