Jump to content

Recommended Posts

This is most likely  a noob question, but... why does it not work?

 

<html>
<head>
</head>

<body style="background-color:#fff;margin:0">
<div style="border-top:1px solid #404040">
1. JS: source file <br />
<script type="text/javascript" src="test2.js"/>
</script>
<br />----<br />

2. PHP: source file<br />
<script language="php" src="test.php"/>
</script>
<br />----<br />

3. JS: script inside<br />
<script type="text/javascript">
   
   document.write('<b></br></br>Hello World</br></b>');
    
</script>
<br />----<br />

4. PHP: script inside <br />
<script language="php">
   
   echo("Hello World");
   print "hello world";
   
</script>

<br />----<br />


</div></div></body></html>

 

with the test.php file in same dir (using MAMP), the test.php does work when loading the file directly:

<?php
     
     echo("Hello World");
?>

PHP only executes on the server, not within the browser.

 

<html><head></head><body>
2. PHP: source file<br />
<?php
include "test.php";
?>
<br />----<br />
4. PHP: script inside <br />
<?php
   echo "Hello World";
   print "hello world";
   ?>
<br />----<br />
</body></html>

 

Both of these would get executed before being sent back to the client, therefore there should be no php code within the page served to the client.

 

 

Agreed, but when loaded on a MAMP install, that should work right?

 

If you execute a PHP script on a local server install then that should be executed, or am I not understanding it correctly?

 

If the file 'test.php' does print, then why doesn't it when included in the html?

Only ever just hearing of MAMP, I see that is basically same as LAMP, or same as installing a web server with PHP and a db (MYSQL).

 

So, no... The web server is standalone (includes the PHP interpreter though), the MYSQL server is also stand alone.

 

You access the web server (as you would on the internet, but just on a local loopback device), therefore you need a web browser (client). The server when required will make connects to the db.

 

ALL PHP is executed in the server...

No browsers ever execute PHP code!!!

If that is the case, then one would not be able to run a drupal (php/mysql) site locally! If the MAMP/LAMP/WAMP is NOT a local server, then it would not be able to run any PHP/MySQL site. Which it does.

 

A MAMP is indeed a local server, so it should execute a PHP. I'm not talking about the browser executing PHP, I'm wondering where the code is incorrect. This is not a server-not-executing problem, but an issue concerning the code. Just don't know where.

Yeah, a local server runs locally, but it's not the web browser (the browser displays the html, js, css, xml, etc, BUT NOT PHP!!!)

 

Here's an image to help you understand... http://www.learnphp-tutorial.com/

 

Yes, I understand what's confusing you... in the source file there is PHP code, but by the time the server sends it out to the client it has been executed and replaced with the output... The client (web browser) then displays what it understands (html, js, xml, css, etc)

 

 

In your original post, your trying to execute php with script tags (html, js, css, type script tags...), those type of tags are client side...

 

Try this file, call it "test.php"

<?php
print "hello world!<br />";
?>

 

Then find it via your server (e.g. DON'T just right click on the file and open with browser),

for instance you may have to put 'localhost' in the address bar, then etc... maybe 'localhost/test.php' if it's in the root directory.

Once displaying in your browser, press 'ctrl+U' to look at the source, see how the php code isn't there, but look at what is...

 

 

p.s. don't even dare question my use of CTRL... lol

 

p.p.s. what I said wasn't wrong! lol, one day you'll look back...

Or even more simply:

 

WEB BROWSER <---> WEB SERVER

 

WEB BROWSER <---> INTERNET <---> WEB SERVER

 

Whether the internet exists between the web browser and web server makes no difference. In both cases the web server is logically remote from the web browser. In the second case, it is also physically remote.

did you try this:

 

<?php

 

  echo("Hello World");

  print "hello world";

 

?>

 

instead of this?

 

<script language="php">

 

  echo("Hello World");

  print "hello world";

 

</script>

 

because i have never seen it before that php is called with <script language="php">

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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