Jump to content

Using include () within the <head> tags


MortimerJazz
 Share

Recommended Posts

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,

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.