• Advertisement
Sign in to follow this  

[web] Problem with PHP & Firefox

This topic is 4428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a function to pull info from a MySQL database, sort it in alphabetical order, and display it as a series of html links. I include this .php file in another .php file and call the function that does the displaying of links. Also, I use these XHTML lines at the very top of the main .php file :
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This is for XHTML 1.0 compliance. In addition, I use the <link> tag within the <head> tag to import a stylesheet that works fine between both browsers, even more so with the XHTML lines above. The problem is that while the function works in IE as intended, Firefox seems to ignore calling the function at all no matter where the call is placed in the file (after the include statement of course). The include statement is within the <body> tag. I've googled for this problem and didn't seem to get anything relevant. So, does anyone here know what the problem could be?

Share this post


Link to post
Share on other sites
Advertisement
The situation you stated is virtually impossible. PHP is a serverside scripting language. There's no way a browser can choose if it does or does not trigger PHP scripts. Would you mind showing us the files? Also, check if the links can be output as HTML. (Look in the page source for the data) If they're displayed, then it's probably your CSS's fault (black text on black background?)

Good luck!

Share this post


Link to post
Share on other sites
Here's the files:

The code to list the links:
<html>
<head>
</head>
<body>
<?php
function onsitelist() {
echo 'onsitelist function called.';
$sql = mysql_connect('localhost','user','passwd');
if(!$sql) return mysql_errno($sql);

$db = mysql_select_db('test',$sql);
if(!$db) return mysql_errno($db);

$query = mysql_query("SELECT sitename, url FROM weblinks ORDER BY sitename");
if(!$query) return mysql_errno($query);

echo '<br>';
while($index = mysql_fetch_array($query, MYSQL_NUM)) {
$name = $index[0];
$url = $index[1];
printf("<a href=%s>%s</a><br>", $url, $name);
}
}

?>
</body>
</html>



The css code:

input {}
input.msg {}
div {}
div.leftinfo {left:0px;top:235px;width:190px;height:375px;
position:absolute;overflow:scroll;border-style:none;border-width:5px;
padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}

div.midinfo {left:200px;top:235px;width:590px;height:375px;
position:absolute;overflow:scroll;border-style:none;border-width:0px;
padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}

div.rightinfo {left:800px;top:235px;width:190px;height:375px;
position:absolute;overflow:scroll;border-style:solid;border-width:0px;
padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}

div.lefttab {position:absolute;left:0px;top:200px;width:190px;height:25px;background-color:#ff0000;border-style:double;
border-color:black;border-width:5px;color:white;font-weight:bold;padding-left:0px;padding-right:0px}
div.midtab {position:absolute;left:200px;top:200px;width:590px;height:25px;background-color:#00ff00;border-style:double;
border-color:black;border-width:5px;color:black;font-weight:bold;padding-left:0px;padding-right:0px}
div.righttab {position:absolute;left:800px;top:200px;width:190px;height:25px;background-color:#0000ff;border-style:double;
border-color:black;border-width:5px;color:white;font-weight:bold;padding-left:0px;padding-right:0px}
div.overlay {}



The main php file that links to both:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Webpage beta 0.1</title>
<link rel="StyleSheet" href="front.css" type="text/css" />
</head>
<body>
<?php
if((include 'ecl_listlinks.php') == 'OK') {
echo 'File included!';
}
?>
<div class="lefttab"><center>On-Site Links</center></div>
<div class="leftinfo">About Me<br />About The Site<br />Archive<br>FAQ<br>Guestbook<br>Pics

n' Such<br>
Recent Posts:<br> #1<br> #2<br> #3<br> #4<br></div>

<div class="midtab"><center>Current Post</center></div>
<div class="midinfo">All the news that's fit to print and then some...</div>

<div class="righttab"><center>Off-Site Links</center></div>
<div class="rightinfo">
<?php
onsitelist();
?>
</div>
</body>
</html>



This is for a blog that I'm planning on starting soon. As far as the CSS, I've seen the stuff display just fine in IE. In Firefox however, nothing is shown. I even tried to highlight the entire page just to make sure the text color didn't match the background color.

Share this post


Link to post
Share on other sites
You do realise, that because you're including a file which already has its own <html> and </html> elements in, there will be an empty body before the one with the data in.

If you use "view source", you should see this error. Firefox is displaying the page correctly, as the body is entirely empty, followed by some rubbish which it is ignoreing.

IE is displaying the page incorrectly because it is showing stuff after </body>

However, the page is badly formed so it doesn't really matter anyway.

You can only have one <html> and <body> element.

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by markr

You can only have one <html> and <body> element.

Mark


Actually since this is XHTML Strict, you can only have one block-level tag, meaning that block tags inside of block tags is also a no-no, and you'll probably want to check that out. IE 6 doesn't have a true understanding of XHTML due to it being as old as it is, Firefox has a lot of the underpinnings for it, and trust me, XHTML Strict is well, strict.

Of course, if you've still got two body/head tags, that's going to throw a DOM error before anything else will, and not only will the code not validate, it won't even begin to display right in a recent browser.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I see you're also missing closing tags for your br elements.

You're not XHTML compliant until this tool says you are. It also helps to get a text editor that will validate while you type (if you get the XML plugin).

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
You do realise, that because you're including a file which already has its own <html> and </html> elements in, there will be an empty body before the one with the data in.


I never thought of that. Thanks for bringing it up. I'll remove the <html> tags from the included .php file and try it again later on today. I suspected Firefox was doing something right considering that it apparently automatically shows pages in xhtml. I say this since removing the xhtml stuff at the top doesn't affect Firefox, but IE is affected.

Quote:
I see you're also missing closing tags for your br elements.

I know, but I was following the xhtml tutorial at www.w3schools.com and that's how it's done there.

Share this post


Link to post
Share on other sites
Okay. I've removed the <html>, <head>, and <body> tags from the included .php file. After that, I removed the center tags and shortened the include line in the main .php file and the validator accepted it. IE still displays it fine and Firefox still refuses to show any PHP. Not even inline PHP works with Firefox; all PHP seems to be ignored there. Maybe it's a configuration error?

Share this post


Link to post
Share on other sites
Configuration errors can't make that happen. There is bound to be something seriously wrong with your HTML.

PHP should not be shown anyway, it should be executed.

Either post the generated HTML somewhere, or make the page publicly available so we can look at it. I'm sure there's a fairly serious problem.

Depending on what content type you use, Mozilla *MAY* use its XML parser to parse XHTML (It usually does not). This will cause the page to fail if it is not well-formed - although the error should be large and obvious.

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
Configuration errors can't make that happen. There is bound to be something seriously wrong with your HTML.

PHP should not be shown anyway, it should be executed.

Either post the generated HTML somewhere, or make the page publicly available so we can look at it. I'm sure there's a fairly serious problem.


How would you suggest I go about posting the generated HTML? PHP's echo statements don't show anything and I don't think printf does either as far as Firefox is concerned. Without that, the best I suppose I could do is copy and paste the same content across every page it is to appear on, but that's not preferable for what I'm trying to do.

Share this post


Link to post
Share on other sites
It's a virtual impossibility that IE is showing something that Firefox isn't if all that's there is PHP.

Suggestion: try
<? phpinfo(); ?> and dump the cache in both browsers.

Share this post


Link to post
Share on other sites
Quote:
Original post by obi-wan shinobi
How would you suggest I go about posting the generated HTML?

Right click -> View Page Source?

Surely if IE is getting some content the Firefox must as well (the opposite case makes no sense).

Share this post


Link to post
Share on other sites
obi wan:

I just copied your code and tried it on my local machine, works fine in IE and firefox.

The only thing i changed was to replace the database connection with a simple echo, so either your SQL query is borked or your firefox is. If its the SQL it wouldnt display in IE though...

Share this post


Link to post
Share on other sites
The call to phpinfo() works in IE, but still not in Firefox. I've cleared the cache in Firefox and it doesn't look like that helps. I'm using PHP 5.0.4 and it's a part of The Uniform Server v3.2a (www.uniformserver.com).

One thing I've noticed is that in IE, View Source shows the generated HTML after PHP processes it. However in Firefox, Page Source still shows the PHP code in my file in a pinkish color and it's italicized, as though it were commented out. Also, on this page (http://www.uniformserver.com/index.php?us=news), Page Source doesn't show any PHP code in a pinkish color. Maybe it is my local configuration settings? No PHP I've come across on the 'net has the problem that my code has.

I know I could just take the generated HTML and make it into a file, but I don't want to have to copy and paste the same content to however many pages I wind up eventually having. Also, this wouldn't work for say, a comments page or the guestbook if the poster wanted to see their message immediately after.

IE View Source:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Webpage beta 0.1</title>
<link rel="StyleSheet" href="front.css" type="text/css" />
now including a file<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
</head>
<body>
body tag entered!<div class="lefttab">On-Site Links</div>
<div class="leftinfo">About Me<br />About The Site<br />Archive<br />FAQ<br />Guestbook<br />Pics n' Such<br />
Recent Posts:<br /> #1<br /> #2<br /> #3<br /> #4<br /></div>

<div class="midtab">Current Post</div>
<div class="midinfo">All the news that's fit to print and then some...</div>

<div class="righttab">Off-Site Links</div>
<div class="rightinfo">
<br><a href="site1.com">site1</a><br /><a href=http://www.mozilla.com>Mozilla</a><br /><a href=site2.com>site2</a><br /><a href=site3.com>site3</a><br /><a href=http://www.yahoo.com>Yahoo!</a><br /></div>
</body>
</html>





Firefox Page Source:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Webpage beta 0.1</title>
<link rel="StyleSheet" href="front.css" type="text/css" />
<?php
echo 'now including a file';
include 'ecl_listlinks.php';
?>
</head>
<body>
<?php
echo 'body tag entered!';
?>
<div class="lefttab">On-Site Links</div>
<div class="leftinfo">About Me<br />About The Site<br />Archive<br />FAQ<br />Guestbook<br />Pics n' Such<br />

Recent Posts:<br /> #1<br /> #2<br /> #3<br /> #4<br /></div>

<div class="midtab">Current Post</div>
<div class="midinfo">All the news that's fit to print and then some...</div>

<div class="righttab">Off-Site Links</div>

<div class="rightinfo">
<?php
onsitelist();
?>
</div>
</body>
</html>





EDIT: gavco98, I just posted and didn't see your message. I'll try that out. I'm using Firefox 1.5 and MySQL 4.1.12a with PHP 5.0.4 and Apache 2.0.54

EDIT 2: I changed the function to echo out each step whether it succeeded or not. IE said they all succeeded, Firefox ignores everything in PHP. I guess my Firefox 1.5 is screwed. Should I uninstall it and reinstall it? Or could it be my Windows XP Home Edition SP2 (which I heard cannot allow local development of ASP)?

[Edited by - obi-wan shinobi on January 6, 2006 7:01:03 AM]

Share this post


Link to post
Share on other sites
Is that really the source you get in PHP? If so, then your server is *seriously* screwed up. Throw it away and get a different server. A server should never, ever, EVER show the actual PHP code to the browser. I suggest you get a real webhost. Check the Forum FAQ for some free/cheap one's.

Share this post


Link to post
Share on other sites
I suppose it is the server. I've downloaded another server, this time from http://www.en.wampserver.com/download.php, called WAMP5. I'll test out the same code on it after installation.

I have a free website ready, but I want to develop locally as a way to save some bandwidth, then upload the complete code to the website's server.

Share this post


Link to post
Share on other sites
It looks like the problem's solved. Using WAMP5 1.6.0, the PHP code shows in both IE and Firefox, and the source shows the generated HTML. The problem was something in Uniform Server 3.2a. If any new issues pop up, I'll mention them, but for now, thanks for the advice everyone!

EDIT: Just tested the code in Uniform Server again and it works too. Looks like the precise problem was that the files were in the wrong directory. Uniform Server has 2 'www' folders in its program files and I placed my code in the wrong one. This is why my Apache directory was empty before, but now it lists the files.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement