 |
 |
PHP in head
|
 |
|
 |
|
Junior Member
Join Date: Jul 2000
Status:
Offline
|
|
Can I put PHP in the head of an HTML page, that is, between the head tags?
Someone told me you couldn't put ASP there and I'm having some trouble with doing it with PHP. I put a dummy PHP statement and it validated, but a more complex one didn't.
What are the rules?
Thanks
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Jul 2003
Location: San Jose
Status:
Offline
|
|
what are you trying to do???? post up some code so we can see what's going on...
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jul 2000
Status:
Offline
|
|
Originally posted by mzllr:
what are you trying to do???? post up some code so we can see what's going on...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
<title>South Bay Mountain Biking Club</title>
A PHP start tag does not show up here on this web page, at least in the preview
<?php
include ("includes/browserDetector.php");
if (browser_is_mac () && browser_is_ie())
echo ("");
else
include ("includes/cssIncluded.inc");
?>
<META name="description" content="SBMBC is a recreational mountain biking club serving the Los Angeles, California area. Regular rides in the Santa Monica and San Gabriel Mountains, and the Angeles and Cleveland National Forests.">
<META NAME="keywords" CONTENT="mountain,biking,dirt,club,bicycle, http://www.corbamtb.com,usinter.net/...ding,trail,los angeles, santa monica mountains,san gabriel mountains,angeles forest, CORBA,SBMBC, off-road, offroad, Bike,Los Angeles,Mountain,Biking">
</head>
this is a the top of a temporary page http://www.sbmbc.com/indexIncludeHeaderTemp.php
browser detect parses what the browser sends back so I can detect IE and give it no css since the css breaks IE Mac. the cssIncludes is the link rels for the css style sheets.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
try this:
[php]
<?php
include ("includes/browserDetector.php");
if (browser_is_mac () && browser_is_ie()) {
echo ("");
}
else
{
readfile("includes/cssIncluded.inc");
}
?>
[/php]
include is used by php to get external functions, not to print out your stylesheet, you use readfile / fopen to do that
--will
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Jul 2003
Location: San Jose
Status:
Offline
|
|
this works, too
[PHP]
<html>
<head>
<?
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") && strstr($_SERVER['HTTP_USER_AGENT'], "Mac_PowerPC")) {
echo "";
} else {
echo "<link href=browser.css rel=stylesheet type=text/css>";
}
?>
</head>
<body>
</body>
</html>
[/PHP]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jul 2000
Status:
Offline
|
|
thanks, lots to learn.
However this doesn't validate if I use
include ("includes/browserDetector.php");
if (browser_is_mac () && browser_is_ie()) {
but does validate if I use the
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") && strstr($_SERVER['HTTP_USER_AGENT'], "Mac_PowerPC"))
I wanted to use the first on, because I was using the result again to put up a note on affected pages. But I can repeat the browserDetector.php and make it work.
thanks
Back in business.
(Last edited by gscarich; Aug 1, 2003 at 12:11 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Jul 2003
Location: San Jose
Status:
Offline
|
|
Originally posted by gscarich:
I wanted to use the first on, because I was using the result again to put up a note on affected pages. But I can repeat the browserDetector.php and make it work.
if you don't want to repeat it, you can always do something like this....
[PHP]
<html>
<head>
<?
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") && strstr($_SERVER['HTTP_USER_AGENT'], "Mac_PowerPC")) {
$bcheck = 0;
} else {
$bcheck = 1;
echo "<link href=browser.css rel=stylesheet type=text/css>";
}
?>
</head>
<body>
<? if ($bcheck != 1) {
echo "Your browser is crap and won't show style sheets";
}
?>
<p>
rest of your page....
</body>
</html>
[/PHP]
you can also set up $bcheck as a session variable so you can use it across all of your pages without having to rerun the "if (strstr...." statement.
makes it a little simpler IMO....
(Last edited by mzllr; Aug 1, 2003 at 04:18 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Jul 2003
Location: San Jose
Status:
Offline
|
|
ok, so i'm bored and have had too much coffee... i put the code together using sessions and it's not any simpler. you still have to run an 'if' statement on the subsequent pages...
but if anyone is interested, here's what i came up with...
index.php
[php]
<?
session_start();
session_register("SESSION_BCHECK");
?>
<html>
<head>
<?
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") && strstr($_SERVER['HTTP_USER_AGENT'], "Mac_PowerPC")) {
$SESSION_BCHECK = 0;
} else {
$SESSION_BCHECK = 1;
echo "<link href=browser.css rel=stylesheet type=text/css>";
}
?>
</head>
<body>
<? if ($SESSION_BCHECK != 1) {
echo "Your browser is crap and won't show style sheets";
}
?>
<p>
rest of your page...
<br>
<a href="page2.php" class="link">go</a>
</body>
</html>
[/php]
then...
page2.php
[php]
<?
session_start();
?>
<html>
<head>
<? if ($SESSION_BCHECK != 1) {
echo "";
} else {
echo "<link href=browser.css rel=stylesheet type=text/css>";
}
?>
</head>
<body>
</body>
</html>
[/php]
and now that i think about it, people won't get the browser check this way if they go directly to page2, skipping the index.... so i guess this post was really just a bunch of rubbish...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|