Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:25:26+00:00 2026-06-07T20:25:26+00:00

I am trying to execute a javascript function from a PHP script by sending

  • 0

I am trying to execute a javascript function from a PHP script by sending a variable over to my javascript function and then it will return the response. I want the PHP script to only echo out the response from the javascript function, so when a client views the source code of my php file, he ONLY sees the response from the javascript function and not the javascript source code.

for example,

I have a javascript function called validate(), and a PHP file called check.php. The client calls the function using the GET method like so,

http://www.myserver.com/check.php?value=test

I then want check.php to send the variable $value over to my javascript function validate(), to perform the following,

response=validate($value)

then the javascript to return the value response to my PHP script and store it within a variable $response, and then it will echo $response. So when I view the source, I will only see the contents within the variable answer.

I can’t find a simple way to do this :S. If I use AJAX I will need to use a div within HTML, but it’s important that ONLY the contents of $response is displayed within the source code?

Could someone point me into what PHP functions I should be using ? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:25:27+00:00Added an answer on June 7, 2026 at 8:25 pm

    PHP normally runs server-side, and Javascript normally runs client side (in the browser).

    In the normal model, the client makes requests to the server, and the server responds. In this case it is not possible for the PHP code to “invoke” the Javascript function directly.

    So what is the solution to your problem?

    In order of preference:

    1. The first, best option is to re-architect so that you do not need to call the javascript validate() function from within PHP. For example, port the Javascript logic to PHP.

    2. If you cannot port, run Javascript on the server side. Node.js runs on server-side on Linux and Windows; if you have Windows/IIS, the easier option is to serve Javascript via ASP classic, which, yes, is still available on current Windows Servers. The PHP program can simply request a local Javascript resource probably via curl; the server invokes the logic and returns the result. In the general case the Javascript need not run on the same server.

    3. Finally, if that’s not an option, you could have the browser execute the validate() on behalf of the server. The PHP can emit the validation function, in a javascript script block, to the browser. PHP can also emit the thing that needs to be validated – a data packet, or whatever it is. The browser can then validate() on that object, and post a message to PHP via AJAX to report the result. But, there’s a security issue here – keep in mind that the client is outside of your control, so there’s a possibility that someone will subvert the client-side validation logic and cause the client to report false results to the PHP server. You cannot count on tihis.

    Therefore you’d need to embed some sort of data integrity check in the transaction – some way that you could insure that the client-side javascript has not been modified. This will be hard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to PHP and JavaScript development, I am trying to execute this
I'm trying to execute a PowerShell script from a c# application. The script has
I am trying to submit a form to execute a php script. But the
I'm trying to execute my controller from javascript using jquery... here is my jquery
I'm using TinyMCE and want to execute a php script get the output and
I'm trying to execute custom JS code from a Firefox extension using: function executeJS(document,
I am trying to execute an arbitrary Javascript function on an Android WebView and
I am trying to emulate a web browser in order to execute JavaScript code
i am just trying to create a link which execute some JavaScript in stead
Trying to execute powershell script in my C# code. Using .NET Framework v. 4.0.30319

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.