homepage Welcome to WebmasterWorld Guest from 54.205.122.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Mozilla Doesn't Understand PHP TYPE
Going nuts getting Mozilla to understand TYPE statement
pgrote

10+ Year Member



 
Msg#: 1030 posted 3:15 am on Nov 10, 2002 (gmt 0)

Hello,

I usually don't give two squirts about validating my HTML, but I am building a site from scratch and have worked for hours tonight on getting it to validate as 4.01 Trans. Guess what? I did it!

I am also testing in Mozilla, Opera, NS4 and IE to ensure that the site works.

Everything looks good and W3C validator nails me on the TYPE statement in my calls to the scripts I use. No problem. I put in the text/cgi and that clears. I put in TYPE=PHP and I am validated.

I go back to testing with the browser, but now Mozilla doesn't display the PHP script output. IE, Opera work fine. NS4 just dies when it hits that part.

I have tried:

TYPE = "PHP"
TYPE = "php"
TYPE = "text/php"

No dice. I have scoured the internet looking for an example, but cannot find one.

Can someone shoot a non-HTML expert a lifeline? I checked the W3C site, but couldn't find specific info on it.

THANKS!

 

Slade

10+ Year Member



 
Msg#: 1030 posted 3:48 am on Nov 10, 2002 (gmt 0)

I'm not quite familiar with what you're trying to do with PHP, and I use it frequently.

Can you post the offending statement?

PHP is all server processed. None of it(unless something goes wrong) is output back to the browser, so you shouldn't be trying to validate it. You should be running the page, getting the result, and validating that.

pgrote

10+ Year Member



 
Msg#: 1030 posted 4:33 am on Nov 10, 2002 (gmt 0)

Thanks, buddy!

Here is the simple statement:

"<script src="idya/ad.php">
</script>"

The validator says I need a TYPE = statement in there. For the SSI CGI scripts I run I added TYPE=text/CGI and it worked.

I did some hunting and if I use TYPE = text/javascript it still works and Mozilla and NS4 like it.

From the snippets I found on the net TYPE = PHP should work, but doesn't in Mozilla or NS4.

Thanks again!

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 5:39 am on Nov 10, 2002 (gmt 0)

PHP should get processed by the server and never seen by the web browser or the validator.

Have you tried replacing '<script language="php">...</script>' with '<?php php code goes here?>'? Either way, no browser or validator should ever see the PHP script code at all. It's server-side scripting, not client-side.

I've never once used <script> tags for my PHP, and I *always* validate my code. It works fine, because what needs to validate isn't whatever.php, it's the output from whatever.php that gets sent to the browser when someone requents whatever.php.

<added> maybe you want <?php include("idya/ad.php");?> </added>

bird

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 2:09 pm on Nov 10, 2002 (gmt 0)

Just because (some of) your HTML is generated by PHP doesn't mean that the browser wants to know anything about that fact. It looks like you're confusing several different things here:
  • <Scripts> are for the browser to process, and are currently only useful with type="text/javascript". Of course that assumes that the included script actually is written in Javascript...
  • <!--#includes--> are for the server to process, and look like code comments to the browser should one ever go out unprocessed. When processed by the server, this can call any file or program, and must produce valid HTML and nothing else for the browser to see.
  • <?php?> tags are invalid HTML as far as the browser is concerned and should never go out unprocessed. This is the only useful way to use PHP code in your documents (and only PHP code). As above, valid HTML should be the only result leaving your server.

Those three items have nothing at all to do with each other, and shouldn't be mixed unless you know exactly what you.

pgrote

10+ Year Member



 
Msg#: 1030 posted 3:25 pm on Nov 10, 2002 (gmt 0)

"Just because (some of) your HTML is generated by PHP doesn't mean that the browser wants to know anything about that fact. It looks like you're confusing several different things here"

I can understand that. I guess what I am asking is when you call a PHP script from an HTML page which TYPE = do you specify?

According to the validator you need to do this. For javascript it's text/javascript and for cgi it's text/cgi. What is it for PHP?

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 5:17 pm on Nov 10, 2002 (gmt 0)

You don´t call a php script from an HTML document. A server can be configured to run certain files through the php parser prior to sending any data to the client. The php parser will look for <? or <?php in those files and execute any code that comes before the closing?>.

A simplyfied step-by-step guide of a request to a PHP script:

  1. A user enters [aaaron.tld...] into the browser´s address bar.
  2. The browser connects to www.aaron.tld and sends a HTTP request (GET /aaron.php).
  3. The server converts the URI to a file name. It recognizes that this file should be processed by PHP.
  4. The file looks like this:
    <html>
    <head><title>AC</title></head>
    <body><p>Aaron <?php echo "rocks!"?></p></body>
    </html>
  5. The file is parsed and executed by PHP.
  6. PHP returns the output
    <html>
    <head><title>AC</title></head>
    <body><p>Aaron rocks!</p></body>
    </html>
    to the web server.
  7. The server sends the output to the browser.
  8. The browser displays the HTML page. It does not execute any PHP code. There is no PHP code to execute.

A simplyfied step-by-step guide of a request to an HTML document containing javascript:

  1. A user enters [aaaron.tld...] into the browser´s address bar.
  2. The browser connects to www.aaron.tld and sends a HTTP request (GET /aaron.html).
  3. The server converts the URI to a file name.
  4. The file looks like this:
    <html>
    <head><title>AC</title></head>
    <body><p>Aaron <script type="text/javascript">document.write("rocks!");</script></p></body>
    </html>
  5. The server sends the content of this file to the browser.
  6. The browser displays the HTML page. When it encounters the script element it looks for the type attribute to determine which local scripting engine should handle this script. The script is parsed and executed.
  7. The final HTML document displayed by the browser looks like this:
    <html>
    <head><title>AC</title></head>
    <body><p>Aaron rocks!</p></body>
    </html>

As you can see both ways produce the same HTML document. In the first example processing was done by the server. In the second example it was the browser on the client side that executed the JavaScript.

Hope this helps.

Andreas

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 8:33 pm on Nov 10, 2002 (gmt 0)

<Scripts> are for the browser to process, and are currently only useful with type="text/javascript". Of course that assumes that the included script actually is written in Javascript...

I think pgrote may have been lead astray by the fact that '<script language="php"> php code here </script>' is valid PHP syntax, as an alternative to '<?php php code here?>'. I don't know why anyone would choose to use that syntax, but it's listed as an option in the laguage reference portion of the manual.

Notwithstanding the fact that it's allowed, I think it's a bad idea. Using a <script> tag would make me expect the contents to be processed by the browser, not the server. In the case of PHP, that's wrong.

As Andreas said, you can't call a PHP file from an HTML file, because the server will skip the step of parsing and executing the PHP, so it never interprets your 'call', and the browser can't.

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 9:13 pm on Nov 10, 2002 (gmt 0)

Interesting info, Andrew.

I didn´t know that <script type="php"></script> was a valid way of escaping PHP from HTML. Thanks for enlightening us.

I don't know why anyone would choose to use that syntax

I was wondering that too after I read your post. php.net has an answer [php.net] for that as well:

<script language="php"> 
echo ("some editors (like FrontPage) don't
like processing instructions");
</script>

Those script tags look exactly like the HTML ones, but they are not, since they are striped off by the PHP engine. Under normal circumstances no UA will ever see them.

Andreas

dingman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1030 posted 9:27 pm on Nov 10, 2002 (gmt 0)

Evidently I should have looked more closely at the example code inside their example tags!

But why would you want to use one of those editors? <duck & cover>

Allen

10+ Year Member



 
Msg#: 1030 posted 3:00 pm on Nov 28, 2002 (gmt 0)

Double-check that you haven't left any invalid HTML like overlapping nested tables or unclosed tables.

Mozilla is fussy about things like that.

HTH

Allen

gsx

10+ Year Member



 
Msg#: 1030 posted 5:33 pm on Nov 28, 2002 (gmt 0)

The type of a php file is text/html.

It should not be used in the script command.

What has been said above stands: You should execute the script server-side, not client-side. Therefore the browser should not see any <script> tags in your code at all.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved