MortimerJazz Posted February 10, 2011 Share Posted February 10, 2011 Are there any problems with calling an include file from within the <header> tags? The reason I'm asking is that I'm trying to load a speficied Style sheet based on a user's location and so I'm running a short script to determine which Style sheet needs to be displayed ... and that script is called from within the header tag. I haven't heard of any problems with doing this in the past, but the script seems to be generating an extra set of <HTML> tags in my source code and I can't figure out why this might be! Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/ Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 you can use PHP anywhere you would use HTML. so there is no problem using php in the <head> Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/#findComment-1172323 Share on other sites More sharing options...
Muddy_Funster Posted February 10, 2011 Share Posted February 10, 2011 can you post up the code from your pages(both the php query and an example of the resulting erronious html) and we can have a look see what the problem may be? Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/#findComment-1172327 Share on other sites More sharing options...
MortimerJazz Posted February 10, 2011 Author Share Posted February 10, 2011 can you post up the code from your pages(both the php query and an example of the resulting erronious html) and we can have a look see what the problem may be? Definitely - thanks for the replies so far. Here's the code I'm using in my index page. You can see the include function four lines from the bottom: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="http://www.mydomain.com/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../style.css" type="text/css" media="screen" /> <? include "functions/getStyle.php"; ?> <link rel="icon" href="http://www.playpokeronline.net/favicon.ico" type="image/x-icon"> <meta name="google-site-verification" content="cwKF364Iet1xHF8hrPgV2prykHYo4I2vN7JU3p2GufQ" /> The getStyle.php contains this code which basically queries a Maxmind Database to determine a player's location. Dependant on the results, the script should then load one of a handful of CSS files. <?php include("geoip.inc"); // Uncomment if querying against GeoIP/Lite City. // include("geoipcity.inc"); $gi = geoip_open("/home/user/public_html/geoIP/GeoIP.dat",GEOIP_STANDARD); $ip=$_SERVER['REMOTE_ADDR']; $country=geoip_country_code_by_addr($gi, "$ip"); geoip_close($gi); switch ($country) { case US: echo '<link rel="stylesheet" href="../style/us.css" type="text/css" media="screen" />'; break; case GB: echo '<link rel="stylesheet" href="../style/gb.css" type="text/css" media="screen" />'; break; case CA: echo '<link rel="stylesheet" href="../style/ca.css" type="text/css" media="screen" />'; break; case AU: echo '<link rel="stylesheet" href="../style/au.css" type="text/css" media="screen" />'; break; default: echo '<link rel="stylesheet" href="../style/default.css" type="text/css" media="screen" />'; } ?> Technically it works - the correct style sheet loads up, but I'm left with this extra HTML tag in the middle of my original <head> tag. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> </body> </html> I hope that makes sense - feel free to ask any more questions if not. I really appreciate the help! Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/#findComment-1172337 Share on other sites More sharing options...
MortimerJazz Posted February 15, 2011 Author Share Posted February 15, 2011 Just wanted to give this a bump? Can anyone help at all? I can't seem to find anything about this anywhere and I'm starting to pull my hair out! Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/#findComment-1174461 Share on other sites More sharing options...
floridaflatlander Posted February 15, 2011 Share Posted February 15, 2011 You have more than one "<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />" ? That's your problem? I have something a little like yours, mine is basically include the switch, switch then defines $css then <link rel="stylesheet" type="text/css" href="../css/<?php echo $css; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/227264-using-include-within-the-tags/#findComment-1174506 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.