Indy
Indy

Reputation: 11

PHP code inside HTML tags

I have a PHP script for my contact form, but my host is not compatible with PHP scripts. Is there a way to get this PHP code in an <script>tag?

Upvotes: 0

Views: 66

Answers (5)

digitai
digitai

Reputation: 1842

It's not a good practice to use server side scripts on the front end, better use client side scripts, say javascript. Server side scripting should be used to serve and consume data, to clean user submitted data mainly.

Please make you a favor and enter javascript . There are many good modern frameworks like ANGULARJS and REACTJS, just to mention my preferred.

Having said that, I answer your question, no it's not possible, but your hosting should support any server, so better ask what server scripting does it provide, because it must. The majority of web hostings provide PHP as default.

Upvotes: 0

tmarois
tmarois

Reputation: 2470

No. If the PHP software itself isn't installed on the server, it isn't available to you to run from any scripts as it is server-side code and has nothing to do with the browser (client-side).

However, if PHP was installed on the server, you can run PHP code within <script> tags as follows:

<script language="php">
  // Your PHP code
</script>

(But that isn't good practice)

Upvotes: 0

user5135328
user5135328

Reputation:

No you can't, because PHP is a server-side language, so if your server doesn't support PHP you can't do anything: tags are for client-side languages, such as Javascript, so in this case are useless. What languages does your server support?

Upvotes: 0

Adam Buchanan Smith
Adam Buchanan Smith

Reputation: 9439

If your server is not compatible with PHP how do you plan one running PHP? To answer your question, no.

However you could look into using node.js

check this out http://www.nodemailer.com/

Upvotes: 0

Anders
Anders

Reputation: 8577

No, there is not. PHP runs on the server, not on the client.

And this is for good reasons. A lot of the things you do with PHP, you wouldn't want to let the client do anyway. For instance loading data from the database - if you gave the client your database password it could get any data from your database.

Some of the things done with PHP could be done in JavaScript instead, but in quite different ways. But not all things could.

If your host does not support PHP, you will either have to live without it or change host.

Upvotes: 1

Related Questions