Having rendering problems with PHP include/ require in webkit browsers and Opera

Messages
89
Reaction score
0
Points
6
I just came across a problem which seems pretty unusual to me. I want to "include" a particular PHP script (loggedStatus.php) in my various pages. Its contents are -
Code:
    <?php
    
    @session_start();
    
    //$username,$password,$databaseName declared
    
    if(isSet($_COOKIE['myCookie']))
    {
    	$dbConnection = mysql_connect("localhost",$username,$password);
    	mysql_select_db($databaseName);
    	$userLoggedIn = mysql_fetch_array(mysql_query("SELECT * FROM usersList WHERE sessionVal='".$_COOKIE['myCookie']."'"));
    	mysql_close($dbConnection);
    	if(!$userLoggedIn['userID']) { echo header("location:../"); exit(); }
    }
    else { header("location:../"); exit(); }
    
    $relLink = "../";
    
    ?>

My site's folder structure is -

Code:
mainFolder

- social

- - index.php
- - profile.php
- - messages.php
- - album.php
- - more files...

- include

- - loggedStatus.php
- - more files...

At the top of my every page (index.php, profile.php, etc), I am "including" the above using <code>include('../include/loggedStatus.php');</code>

But whenever I do that, I find a space at the top before my menu bar appears.
This occurs only in the webkit browsers (Chrome, Safari, Opera), and not in Firefox.

Everything else appears to be fine.

But the space disappears when I replace the
Code:
include('../include/loggedStatus.php');
with the full script!

Am I missing something, or is it a bug in the webkit engine?
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
The webkit engine knows nothing about your PHP, only the HTML that results from it. If the rendering engine is gives two different results depending on whether you're including the script or adding it inline, that means that the HTML you're producing is different, resulting in a different DOM to flow and render. Since both webkit and Opera are seeing the difference (and Opera is usually a "strict interpreter", at least in the pre-webkit versions), the difference is probably something that should result in a space on the displayed page (unless the engine is actively fixing errors). You'll need to look at the HTML source to see what the difference is.
 
Messages
89
Reaction score
0
Points
6
Found the problem. The source code for the Chrome version contains a certain character (shown in the image attached) in line #2, which does not occur in the Firefox code.

By the way, all my pages are encoded in UTF-8 format. So I just changed the encoding of the loggedStatus.php page to ANSI. That erased the problem.

However I don't have any idea how this character is popping up. And I would really like to know.
 

Attachments

  • bugCaught.png
    bugCaught.png
    22.9 KB · Views: 4

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
What you've got there is probably a BOM (a byte order mark, which tells the system whether the text was encoded in Big-endian or Little-endian for multibyte characters), which is normally an unprintable character. Your editor will usually give you the option to encode as UTF-8 without a BOM. Do note that the BOM can prevent any header activity from working correctly as well, since it is written to the browser before any of your script runs if output buffering is not enabled (meaning that the page headers have already been sent before you set any header variables).

Oh -- it's not that it's not there in Firefox, it's just not being shown to you. And it's likely that Firefox sees it as a page bug and is ignoring it. It's not supposed to do that, but there's a long, long history of making incorrect markup render in a "do what I meant, not what I said" sort of way on the web.
 
Last edited:
Top