Jump to content

include("header.php"); Messing With CSS Design!


justlukeyou

Recommended Posts

I am come across a very odd situation when I include a connnet.php file.  For some reason it messes up the layout of the page.  However when I enter the connect code onto the page it looks fine.

 

include("connect.php");

 

What is also strange is that when I include the header and footer it works fine.  For some reason it is just when I include the connect.php file.

 

Is this because it is above the CSS file?

 

include("header.php");

 

include("footer.php");

Link to comment
Share on other sites

Basically when include a connect.php file as central file it interferes with layout of the page.  Interfering with the border.

 

The strange thing is that when I include other files these work completely fine. 

 

Also, the page works fine in Firefox but it in Internet Explorer and Google Chrome it messes the page up.

Link to comment
Share on other sites

My guess is that connect.php has some whitespace before <?php or after ?>

This would be my guess as well. If you have a DOCTYPE declaration, any white-space before this declaration can cause the type to be ignored, which throws some browsers into HTML 4/quirks mode. This will completely mess with your CSS.

 

IE is notorious for finding any flaw as an excuse to mess with you! Declare XHTML, but have any flaw in your code, it will throw IE into HTML 4/quirks mode. White space before the DOCTYPE, quirks mode. Use HTML 5, quirks mode (j/k, but it seems like it sometimes!)

Link to comment
Share on other sites

What is the best way to do this

 

You need to find what is actually causing the problem and fix it.

 

What exactly is in your connect.php file? xxxxxx out any sensitive information, but don't change any of the actual syntax when you post it. Post the opening and closing php tags as well.  Also, post your main file from the first line of it through and including the include statement.

 

Have you checked to make sure that there are no characters in your connect.php file before the <?php tag or after the ?> tag? Also, if your connect.php file has been saved with the BOM (Byte Order Mark) characters, it will likely mess up your page.

 

When you do a 'view source' of your page in your browser, what exactly is present in the output at the point where the connect.php file was included when the page was generated?

Link to comment
Share on other sites

Hi,

 

This is my connect file.  I have tried to remove as much white space as possible.  It works fine in Firefox, its just IE and Chrome which it doesn't like.

 

 

<?php set_time_limit(0);
ignore_user_abort(true);
ini_set("allow_url_fopen", "ON");
ini_set("memory_limit", "128M"); // = 134217728 bytes
$host = "localhost";
$username = "xxxx";
$password = "xxxx";
$database = "xxxx";
mysql_connect($host, $username, $password);
mysql_select_db($database); ?>

 

 

<?php  include("connect.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Link to comment
Share on other sites

Try putting the doctype on the same line as the include. If it is still messed up, view the source that the browser is getting.

<?php  include("connect.php"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Link to comment
Share on other sites

Hi,

 

I have problem where by in Chrome and IE it pushes down the start of page because I am either inserting a connect file or simple adding my connect code.  I found something call ob_start however this no affect.

 

Has anyone heard of it or use it?

Link to comment
Share on other sites

This is very basic but you will have to excuse me. Chrome and IE and causing me major problems as when I ever include a connect file or even add the connect code at the top of the page it puts spaces at the top of the page.

 

When I just use header.php and footer.php it works fine so I know its just the db connection code.

 

So I am setting out my page wrong, is there a standard way to set out pages with the connect.php file or db access code at the top?

 

In Firefox I dont get this problem at all!  Is there a way I set out the page to avoid this.  Its giving me serious headaches.

 

<?php 
include("connect.php");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Page Title</title>
<meta name="keywords" content="keywords" />
<meta name="description" content="Website Content" />
<link rel="stylesheet" href="/stylesheet.css" type="text/css" />
</head>

<?php 
include("header.php");
?>

**Stuff In Here

<?php 

include("footer.php");

?>

Link to comment
Share on other sites

My issue is that Chrome and IE keep putting a gap at the top of my page whenever I insert something.

 

I have tried removing all the white space possible  and when I view the source the head is at the top.

 

I have a topic on it...

 

http://www.phpfreaks.com/forums/index.php?topic=359671.0

 

 

Its really getting on my nerves.  I cant believe how stupid an error it is.  There has to be a way around it.

 

 

Link to comment
Share on other sites

I found something call ob_start however this no affect.

 

Why don't you debug what is causing the problem, as has already been suggested in your existing thread for this problem.

 

edit: fixed spelling error, once I found where the thread went to

Link to comment
Share on other sites

I found something call ob_start however this no affect.

 

Why don't you debug what is causing the problem, as has already been suggested in your exiting thread for this problem.

 

Your right, I should do that.  To be totally honest I thought I was setting the page up wrong and that there was a different way to set the page up which everyone else uses.  I also wanted to get cracking with learning PHP but your right I need to deal with this issue.

 

How do I check if I am using BOM (Byte Order Mark)? which could mess things up.  My files are currently in UTF-8

Link to comment
Share on other sites

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.