Jump to content

need help with a strange behaviour in php


Go to solution Solved by mac_gyver,

Recommended Posts

hi, guys im trying to debug this issue for 3 days straight and still i have no starting point in the web for this so came here. the problem is everytime when i try to open my home page it displays a 'g' at the top of the document before the header. i dont know where that bug is coming from in my code. the chrome developer tools shows that it  loads in the body tag and the page source showed it at the top of the page. Hence double checked the header file where the problem lies but still no solution. please help me out guys.

<?php
include 'dbconfig.inc.php';
error_reporting(0);
$thispage=  basename($_SERVER['PHP_SELF']);
$thisgroup="";
$aglist="";
$mglist="";
if ($thispage=="group.php") {
    if (isset($_GET['g'])) {
$thisgroup=htmlentities($_GET['g']);
$_SESSION['group']=$thisgroup;

  
    }   }
  
//if (isset($_SESSION['group'])) {}
    $query="select * from groups";
    $stmt11=$conn->prepare($query);
   $stmt11->execute();
   $g_check=$stmt11->rowCount();
   $fetch=$stmt11->fetchAll();
   
   if ($g_check>0) {
       foreach ($fetch as $row) {
          
           $aglist.="<span float='right'><td border='solid 2px #'><a href='group.php?g=".$row['name']."'><img src='group/".$row['g_id']."/".$row['logo']."' alt='".$row['name']."' title='".$row['name']."' width='50' height='50'>{$row['name']}</a></td></span>";
        }
}
   $sql1="select gm.*, g.* from gmembers as gm left join groups as g on g.creator=gm.mname where gm.mname=:session ";
   $stmt1=$conn->prepare($sql1);
   $stmt1->bindValue(":session",$_SESSION['uname']);
   $stmt1->execute();
   //$g_check1=$stmt1->rowCount();
   $g_fetch=$stmt1->fetchAll();
  
    $sql="select gm.*,g.* from groups as g left join gmembers as gm on g.name=gm.gname where gm.mname=:session_uname ";
    
$stmt=$conn->prepare($sql);
//$stmt->bindValue(":session",$_SESSION['group']);
$stmt->bindValue(":session_uname",$_SESSION['uname']);
$stmt->execute();
$fetch1=$stmt->fetchAll();
$g_check1=$stmt->rowCount();
   if($g_check1>0){
       foreach ($fetch1 as $row) {
        
           $mglist .="<td border='solid 2px #'><a href='group.php?g=".$row['gname']."&v=".$_SESSION['uname']."'><img src='group/".$row['g_id']."/".$row['logo']."' alt='".$row['gname']."' title='".$row['gname']."' width='50' height='50'>".$row['gname']."</a></td><br><hr>";
   
       }
   }
 
if(isset($_SESSION['app'])){
$_sql="select count(pm_id) from private_message where (receiver=:sess_uname and has_replies='1' and sread='0') limit 1";
$stmt=$conn->prepare($_sql);
$stmt->bindValue(":sess_uname", $_SESSION['uname']);
$stmt->execute();
$numrows_n=$stmt->fetch();

if ($numrows_n[0]>0) {
    $pm_n="<a href='private_message.php?u=".$_SESSION['uname']."'><span style='background: white; height:30px; width:30px;'><img  src='img/email153.png' alt='private_message'></span></a>";
}
 else {
$pm_n="<a href='private_message.php?u=".$_SESSION['uname']."'><img src='img/email153.png'  alt='private_message_alert'></a>";
}

    $sql="select count(friend_id) from friends where friend_two=:sess_uname and accepted='0'";
    $stmt1=$conn->prepare($sql);
    $stmt1->bindValue(":sess_uname", $_SESSION['uname']);
    $stmt1->execute();
    $request_count=$stmt1->fetch();
    $count_friend=$stmt1->rowCount();
    if($request_count[0]>0){
    $new_friends="<a href='all_notifications.php'><span style='background: white; height:33px; border-radius:10px; width:30px;'><img src='img/users.png' style='height:25px; width:27px;' alt='new_friends_alert'></span></a>";
    }else{
     $new_friends="<a href='all_notifications.php'><img src='img/users.png' style='height:25px; width:27px;' alt='new_friends_alert'></a>";   
    }
    
    
echo '
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>Protected Area.</title>
<link href="http://localhost/project/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="http://localhost/project/css/custom.css" rel="stylesheet" type="text/css"/>
<link href="http://localhost/project/css/jquery.fancybox.css" rel="stylesheet" type="text/css"/>
<script src="http://localhost/project/js/jquery-1.11.3.js" type="text/javascript"></script>
<script src="http://localhost/project/js/bootstrap.min.js" type="text/javascript"></script>
 <script src="http://localhost/project/js/custom.js" type="text/javascript"></script>
<script src="http://localhost/project/js/respond.js" type="text/javascript"></script>
<script src="http://localhost/project/tinymce/js/tinymce/tinymce.min.js" type="text/javascript"></script>
<script src="http://localhost/project/js/tinymce.init.js" type="text/javascript"></script>
<script src="http://localhost/project/js/jquery.fancybox.js" type="text/javascript"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css"/>
    <link type="text/css" rel="stylesheet" href="css/jquery-ui.structure.css"/>
    <link type="text/css" rel="stylesheet" href="css/jquery-ui.theme.css"/>

    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" type="text/javascript"></script>
    <script src="js/store.min.js" type="text/javascript"></script>
    <script src="js/jquery-idleTimeout.js" type="text/javascript"></script>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
<div class="row">
<header class="header-custom visible-phone visible-tablet visible-desktop">
<div class="head-col-left-custom ">LOGO!</div>
<div class="head-col-middle-custom">
<table>
<td >
<tr class="pull-left">
<input type="text" name="search" class="pull-left input-custom1 search" width="50%" height="30" placeholder="Search by First , Last or username or group name">  
</tr>
<br>
<tr>
<div mysearch="mysearch" id="result">
</div>
</tr>
</td>
<td>    </td><td class="pull-right"><a href="home.php?u='.$_SESSION["uname"].'">'. $_SESSION["uname"].'</a> | '.$pm_n.' | '.$new_friends.'</td>
<td ><div class="dropdown">
<button type="button" class="btn btn-danger dropdown-toggle pull-right" data-toggle="dropdown" aria-expanded="true" >Settings<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="http://localhost/project/all_notifications.php" >All Notifications</a></li>
<li><a href="http://localhost/project/create_group.php" >Create a group</a></li>
<li role="separator"class="divider" ></li>
<li><a href="http://localhost/project/options/logout.php" >Logout</a></li>

</ul>
</div>
</td>
</table>
</div><br>
 
</header>
                      </div>
                      <br>
';

}
 else {
    error_reporting(0);
echo ' 
<doctype html!>
<html>
    <head>
<meta charset="UTF-8">
<title>Activation Area.</title>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="css/custom.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
 <script src="js/custom.js" type="text/javascript"></script>
<script src="js/respond.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
<div class="row"><header class="header-custom1 visible-phone visible-tablet visible-desktop">
<div class="head-col-left-custom hidden-xs ">LOGO!</div>
<div class="head-col-middle-custom1">
<form action="includes/login.inc.php" method="post">
<tr><td>Username: <input type="text" required placeholder="Username" class="input-custom input-group-sm input-sm" name="unamel"> </td></tr>
<tr><td>Password:<input class="input-custom input-group-sm  input-sm" type="password" name="passl" required placeholder="Password">  
<input type="submit" name="submit-login" value="login" class="btn btn-warning btn-danger-custom"> | <a href="forgotpass.php">?Forgot Password</a></p></td></tr>
</form>
</div>
</header>
</div>

';

 }

post-185217-0-18644600-1454369284_thumb.png

post-185217-0-45428800-1454369299_thumb.png

Edited by shan2batman
  • Solution

it's probably something in the 'dbconfig.inc.php' file.

 

Hence double checked the header file where the problem lies

 

 

or if the posted code is being included/required into another file, it's coming from something in the main file.

Try this:

 

First, get rid of the stupid

error_reporting(0);
That tells PHP to ignore any possible errors.

 

Then try your script and see anything happens.

 

If not, just before the echo on line 79 add a line

header("Content-Type: text/html");
Then look for an error message telling you it failed because of output somewhere.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.