Css en URL
Komt ik via URL 1 op de site dan kiest hij stylesheet 1 en kom ik met URL 2 op de site kiest hij stylesheet 2
Hm, kan niet echt vinden waar die staan?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<script type="text/javascript">
function init () {
if (document.referrer = 'http://www.jouwsite.nl/pagina1.php') {
document.write ("@import 'style1.css';");
}
else if (document.referrer = 'http://www.jouwsite.nl/pagina2.php') {
document.write ("@import 'style2.css';");
}
}
window.onload = init;
</script>
</style>
</head>
<body>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<script type="text/javascript">
function init () {
if (document.referrer = 'http://www.jouwsite.nl/pagina1.php') {
document.write ("@import 'style1.css';");
}
else if (document.referrer = 'http://www.jouwsite.nl/pagina2.php') {
document.write ("@import 'style2.css';");
}
}
window.onload = init;
</script>
</style>
</head>
<body>
</body>
</html>
Je bedoelt de PHP_REFERER?
Nee, dit gaat over de JavaScript referrer (die daar ineens met dubbel 'r' geschreven wordt).
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?
if ($_SERVER['HTTP_HOST'] == "www.xxxx.nl")
{
echo "<link href='style_nl.css' rel='stylesheet' type='text/css'>";
}
elseif ($_SERVER['HTTP_HOST'] == "www.xzzx.nl")
{
echo "<link href='style_nl.css' rel='stylesheet' type='text/css'>";
}
elseif ($_SERVER['HTTP_HOST'] == "www.xxxx.eu")
{
echo "<link href='style_eu.css' rel='stylesheet' type='text/css'>";
}
else {
echo "<link href='style.css' rel='stylesheet' type='text/css'>";
}
?>
if ($_SERVER['HTTP_HOST'] == "www.xxxx.nl")
{
echo "<link href='style_nl.css' rel='stylesheet' type='text/css'>";
}
elseif ($_SERVER['HTTP_HOST'] == "www.xzzx.nl")
{
echo "<link href='style_nl.css' rel='stylesheet' type='text/css'>";
}
elseif ($_SERVER['HTTP_HOST'] == "www.xxxx.eu")
{
echo "<link href='style_eu.css' rel='stylesheet' type='text/css'>";
}
else {
echo "<link href='style.css' rel='stylesheet' type='text/css'>";
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$ext = strrchr($_SERVER['HTTP_HOST'], '.');
switch($ext)
{
case '.nl' :
echo '<link href="style_nl.css" rel="stylesheet" type="text/css">';
break;
case '.eu' :
echo '<link href="style_eu.css" rel="stylesheet" type="text/css">';
break;
default :
echo '<link href="style.css" rel="stylesheet" type="text/css">';
}
?>
$ext = strrchr($_SERVER['HTTP_HOST'], '.');
switch($ext)
{
case '.nl' :
echo '<link href="style_nl.css" rel="stylesheet" type="text/css">';
break;
case '.eu' :
echo '<link href="style_eu.css" rel="stylesheet" type="text/css">';
break;
default :
echo '<link href="style.css" rel="stylesheet" type="text/css">';
}
?>
ps. Vergeet ook niet dat html het gebruik van dubbele quotes eist. Om een string in php zet je enkele quotes, op die manier hoef je de dubbele van de html niet te escapen.