-1

I know this question has been asked before but I cannot find a way out of this. I need to go to sign in page once user logs out but it stays in member page and shows the error. I need to go to the page under the first conditional in member page. What can I do? Please help. Been trying many stuffs. May be I missed something. When I log out and again load member page it gives that error below while staying in member page:

Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd4/169/2461169/public_html/header.php:1) in /storage/ssd4/169/2461169/public_html/member.php on line 6

member page

<?php
include ("db_con.php");
include ("index.php"); 
if(!isset($_SESSION['email']))
{
header('location:https://goldentitles.000webhostapp.com/signin.php');
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Member Area</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/member.css">
<link rel="stylesheet" type="text/css" href="css/inpagetable.css">

<script type="text/javascript" src="js/member.js"></script>
</head>
<body>

<!--member tabs-->

<div class="tabmember">
<button class="tablinks" onclick="opentab1(event, 'profile')">Profile</button>
<button class="tablinks" onclick="opentab2(event, 'edit')">Edit</button>
<button class="tablinks" onclick="opentab(event, 'myorder')">My Order</button>
<a href="logout_user.php"><button class="tablinks">Log out</button></a>

</div>
<!--profile tab-->
<div id="profile">
<?php 


$email=filter_var($_SESSION['email'],FILTER_SANITIZE_EMAIL) ;

$user_query="select * from user where email='$email'"; 

$run_query=mysqli_query($dbcon,$user_query);  

if(mysqli_num_rows($run_query)>0)  
{  



echo' <table border="2" class=inpagetable>
<thead>
<tr>
<th>id</th>
<th>email</th>
<th>status</th>
<th>zip</th>
<th>name</th>
<th>password</th>
<th>address</th>

<th>country</th>
<th>expires</th>

</tr>
</thead>';


while( $row = mysqli_fetch_assoc( $run_query)){
echo "<tbody><tr><td>{$row['id']}</td><td>{$row['email']}</td><td>{$row['status']}</td><td>{$row['zip']}</td><td>{$row['name']}</td><td>{$row['password']}</td><td>{$row['address']}</td><td>{$row['country']}</td><td>{$row['expires']}</td></tr></tbody>\n";
}

echo '</table>';

}
else {echo"<script>alert('error retrieving from database! Contact admin!')</script>"; 


}

//close con
mysqli_close($dbcon);

?>

<button class="mainpage" onclick="mainpg()">Back to Main Page</button><br>


</div>
<!--edit form-->
<div id="edit">



<form id="actform" action="edit_user.php" method="post">



<input type="text" id="email" name="email_" placeholder="Your new email.."> 


<input type="text" id="name" name="fullname" placeholder="Your new full name..">
<input type="password" id="pass" name="password" placeholder="Your new password..">


<input type="text" id="address" name="fulladdr" placeholder="Your new full address..">


<input type="text" id="zip" name="zipcode" placeholder="Your new zip code..">


<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
</select>

<input type="submit" name="confirm" value="Confirm">

</form>
</div>
</body>
</html>

My header page

<!DOCTYPE html>
<html>
<head>
       <title>Golden Titles</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/header.css">
</head>
<body>

<div class="top">



    <div id="header">
        <a href="signin.php"> Sign in</a> |
        <a href="signup.php"> Sign up </a> |
        <a href="#"> Help </a> <br>

    </div>

    <div id="smedia">

        <a href="https://www.facebook.com" ><img src="http://www.ransomesjacobsen.com/themes/jacobsen/images/icons/facebook-icon-small.png" alt="facebook" id="fb"> </a>

        <a href="https://www.twitter.com" > <img src="http://www.freeiconspng.com/_img/icon-top-twitter.png" alt="twitter" id="tw"></a>
        <a href="https://www.instagram.com" > <img src="http://dunedin.art.museum/templates/dpag/images/instagram-icon.png" alt="instagram" id="ins"></a>


    </div>

    <div id="search">
    <form action="search.php" method="post">
    <input type="search" name="searchdb" placeholder="enter book name only">

    </form>
</div>

</div>
<div id="kng">
        <img src="img/kng.jpg" alt="knowledge is power">
    </div>
</body>
</html>
chris85
  • 23,846
  • 7
  • 34
  • 51
  • Show `db_conf.php` and `index.php` code – Pankaj Makwana Aug 04 '17 at 12:20
  • where is header.php included? Is that in index.php? If so: why is there twice a html doctype etc in one page. apart from that: your redirect should be done BEFORE you start outputting any html – Ivo P Aug 04 '17 at 12:24

1 Answers1

0

change your code like below.

<?php
//check condition before page included
if(!isset($_SESSION['email']))
{
header('location:https://goldentitles.000webhostapp.com/signin.php');
exit(); //<---add exit
}
include ("db_con.php");
include ("index.php"); 

?>

<!DOCTYPE html>
<html>
<head>
<title>Member Area</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/member.css">
<link rel="stylesheet" type="text/css" href="css/inpagetable.css">

<script type="text/javascript" src="js/member.js"></script>
</head>
<body>

<!--member tabs-->

<div class="tabmember">
<button class="tablinks" onclick="opentab1(event, 'profile')">Profile</button>
<button class="tablinks" onclick="opentab2(event, 'edit')">Edit</button>
<button class="tablinks" onclick="opentab(event, 'myorder')">My Order</button>
<a href="logout_user.php"><button class="tablinks">Log out</button></a>

</div>
<!--profile tab-->
<div id="profile">
<?php 


$email=filter_var($_SESSION['email'],FILTER_SANITIZE_EMAIL) ;

$user_query="select * from user where email='$email'"; 

$run_query=mysqli_query($dbcon,$user_query);  

if(mysqli_num_rows($run_query)>0)  
{  



echo' <table border="2" class=inpagetable>
<thead>
<tr>
<th>id</th>
<th>email</th>
<th>status</th>
<th>zip</th>
<th>name</th>
<th>password</th>
<th>address</th>

<th>country</th>
<th>expires</th>

</tr>
</thead>';


while( $row = mysqli_fetch_assoc( $run_query)){
echo "<tbody><tr><td>{$row['id']}</td><td>{$row['email']}</td><td>{$row['status']}</td><td>{$row['zip']}</td><td>{$row['name']}</td><td>{$row['password']}</td><td>{$row['address']}</td><td>{$row['country']}</td><td>{$row['expires']}</td></tr></tbody>\n";
}

echo '</table>';

}
else {echo"<script>alert('error retrieving from database! Contact admin!')</script>"; 


}

//close con
mysqli_close($dbcon);

?>

<button class="mainpage" onclick="mainpg()">Back to Main Page</button><br>


</div>
<!--edit form-->
<div id="edit">



<form id="actform" action="edit_user.php" method="post">



<input type="text" id="email" name="email_" placeholder="Your new email.."> 


<input type="text" id="name" name="fullname" placeholder="Your new full name..">
<input type="password" id="pass" name="password" placeholder="Your new password..">


<input type="text" id="address" name="fulladdr" placeholder="Your new full address..">


<input type="text" id="zip" name="zipcode" placeholder="Your new zip code..">


<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
</select>

<input type="submit" name="confirm" value="Confirm">

</form>
</div>
</body>
</html>
B. Desai
  • 16,414
  • 5
  • 26
  • 47