justlukeyou Posted May 16, 2012 Share Posted May 16, 2012 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"); Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/ Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 Maybe. Need more info. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1346122 Share on other sites More sharing options...
justlukeyou Posted May 16, 2012 Author Share Posted May 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1346127 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 My guess is that connect.php has some whitespace before <?php or after ?> Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1346134 Share on other sites More sharing options...
rythemton Posted May 16, 2012 Share Posted May 16, 2012 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!) Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1346137 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 Yup! Another reason using the header / footer include model is antiquated. Better to use a a templating system with an output buffer to prevent any output before the template renders. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1346158 Share on other sites More sharing options...
justlukeyou Posted May 20, 2012 Author Share Posted May 20, 2012 Thanks, I have tried around 10 variations of this. I have seen many examples where it says you include a .connect.php. What is the best way to do this, should I just remove the DOCTYPE declaration? Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347004 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2012 Share Posted May 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347009 Share on other sites More sharing options...
justlukeyou Posted May 20, 2012 Author Share Posted May 20, 2012 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"> Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347038 Share on other sites More sharing options...
rythemton Posted May 21, 2012 Share Posted May 21, 2012 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"> Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347169 Share on other sites More sharing options...
justlukeyou Posted May 21, 2012 Author Share Posted May 21, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347388 Share on other sites More sharing options...
justlukeyou Posted May 21, 2012 Author Share Posted May 21, 2012 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347412 Share on other sites More sharing options...
Kays Posted May 21, 2012 Share Posted May 21, 2012 Whitespaces do tend to happen when you close php tags. Hence, for LIBRARY use-only files, don't close the ending php tag. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347415 Share on other sites More sharing options...
justlukeyou Posted May 21, 2012 Author Share Posted May 21, 2012 So what does that mean? What are LIBRARY use-only file. Is there a best practice way to set up a file to avoid this issue completely? The only way I have found to avoid is to use no includes at all! Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347417 Share on other sites More sharing options...
trq Posted May 21, 2012 Share Posted May 21, 2012 It has it's uses. I'm not sure what your issue is though. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347426 Share on other sites More sharing options...
justlukeyou Posted May 21, 2012 Author Share Posted May 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347428 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2012 Share Posted May 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347429 Share on other sites More sharing options...
Pikachu2000 Posted May 21, 2012 Share Posted May 21, 2012 Threads merged. Opening multiple threads for the same problem will only make it harder to get an answer. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347431 Share on other sites More sharing options...
justlukeyou Posted May 21, 2012 Author Share Posted May 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347432 Share on other sites More sharing options...
smoseley Posted May 21, 2012 Share Posted May 21, 2012 Just include connect.php AFTER your doctype. That should fix any whitespace issues. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347444 Share on other sites More sharing options...
justlukeyou Posted May 22, 2012 Author Share Posted May 22, 2012 Brilliant thanks, I shall try that ASAP. Does anyone have this problem? Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347542 Share on other sites More sharing options...
smoseley Posted May 22, 2012 Share Posted May 22, 2012 Everyone has this problem at some point or another. Quote Link to comment https://forums.phpfreaks.com/topic/262639-includeheaderphp-messing-with-css-design/#findComment-1347564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.