0

I have kind of a weird problem, which doesn't make any sense at all, i have a web page and for some reason there is a blank whitespace at the top of it, by removing code i have pinned it down that the problem is this include:

<?php
    error_reporting(0);
include 'inc/inc.php';
include ("logMeIn.php");
?>

namely the logMein.php file, here are the contents of the file:

<?php
session_start();

include 'inc/inc.php';


$check = $conn->query("SELECT active FROM admin");
$check = $check -> fetch();
if ($check['active'] == 0){

exit("Вы превысили количество попыток, администратор заблокирован, свяжитесь с   разработчиком");
}


if(isset($_POST['loginBtn'])){

$user = $_POST['loginName'];
$pass = md5($_POST['loginPass']);

$result = $conn -> query("SELECT adminName, adminPass FROM admin WHERE adminName ='$user' AND adminPass = '$pass'");
$count = $result->rowCount();
if($count != 0){

    $_SESSION['admin'] = "admin";
    $_SESSION['logAttempt'] = 0;
}else{


    $_SESSION['logAttempt'] ++;
}


if($_SESSION['logAttempt'] > 3){

    $conn -> query("UPDATE admin SET active = 0");
}


header('location:adminka.php');


}


  if(isset($_POST['logOutBtn'])){

  unset($_SESSION['admin']);


  header('location:adminka.php');
}


?>

so it just validates the login and stuff, please don't judge the code, as i am new to php and mysql, i know its not secure. but here is the weird part, as you can see i've turned all the error reporting off this was intentional, i've tried deleting just the line that includes the file, the whitespace is gone, so i try to find something that could be the problem in the file, found nothing, deleted ALL of the contents in the logMeIn.php file, the whitespace is STLL there, how is this possible?

ps. if i let the errors in, there is no error, just this whitespace, it doesn't happen in mozilla, but chrome and ie do have this thing. Any help?

user2209644
  • 701
  • 1
  • 9
  • 21

2 Answers2

2

Try removing the ?> in pure php files. There might be a stray space or new line after you close the php section. Never closing your php sections will solve that issue.

If it's a BOM issue, you'll have to remove them from your files see this SO answer for more details.

Community
  • 1
  • 1
T0xicCode
  • 4,583
  • 2
  • 37
  • 50
  • Indeed, as indicated by the official documentation, omitting the closing tag in pure PHP file is preferable. http://www.php.net/manual/en/language.basic-syntax.phptags.php – Th. Ma. Feb 09 '14 at 21:42
  • tried that, no luck, as you can see from my question, i have tried deleting all of the contents leaving just a blank document, which still left the whitespace there – user2209644 Feb 09 '14 at 21:43
  • 2
    There might be a unicode BOM at the start of the file. Notepad loves to add them when you save files as utf8. – T0xicCode Feb 09 '14 at 21:44
  • im using notepad++ and indeed, the file is in utf8, is there any way i can remove it? – user2209644 Feb 09 '14 at 21:45
  • @user2209644 You should also turn on error_reporting to figure out where the extra space is. – T0xicCode Feb 09 '14 at 21:52
  • the error reporting is usually on, of course, i have done that only to see if making the file blank is going to solve the problem, which it didn't, usually there is no error, even with error reporting on – user2209644 Feb 09 '14 at 21:54
  • it really was the BOM issue, damn it, wasted hours on this, thank you very much everyone! i'll accept the answer as soon as i am allowed to – user2209644 Feb 09 '14 at 22:00
0

Where do you see the empty whitespace? Have you tried this?

<?php error_reporting(0); include 'inc/inc.php'; include ("logMeIn.php"); ?>

Putting everything in a single line to see if that helps?

Also, I noticed that you have actually included the inc/inc.php file twice, which I'm guessing is not necessary. It's being included in your main file and your logMeIn.php file. Have you tried looking at the inc/inc.php file for any whitespace?

Armin
  • 1,736
  • 4
  • 19
  • 35
  • i have tried that, doesn't remove the whitespace, also, inc file is fine, i am using it on other pages and there is not whitespace, it is definitely the logmein file – user2209644 Feb 09 '14 at 21:52