0

I have hard time finding a solution to execute php script on button click. I have this code.

  Dim tempfilename As String = "C:\test.php"
    Dim startInfo As New ProcessStartInfo("php.exe")
    startInfo.CreateNoWindow = False
    startInfo.FileName = TempFileName
    Dim returnvalue As Object
    startInfo.WindowStyle = ProcessWindowStyle.Minimized
    Process.Start(startInfo)

I dont now how to write the line that executes the script For ex. in cmd: php.exe test.php

How to write this command in vb , where to add it ?

  • c# but basically the same: https://stackoverflow.com/questions/1469764/run-command-prompt-commands – Steve May 30 '17 at 13:00

1 Answers1

1

PHP a Server-Side Language

A reminder of the most important:

PHP was designed to be a Server-side language, whereas HTML,CSS,JS, are client side languages. Hence PHP needs a server. But this property of PHP provides a lot of Security to the user data!

If you want to be able to use PHP localy on your machine you need a server.

Nowadays WAMP (Apache, MySQL, PHP on Windows) is a good solution.


Local Server

Once a local server created you can simply make a WebRequest to:

127.0.0.1/myfile.php

The response will be your script result.


Comand Line PHP

It is also possible to run PHP from the command line but you need to remember that this means you need to have installed the latest version of PHP if thats the case for example using WAMP you would do something like this:

First check the path of the php.exe:

c:\wamp\bin\php\php5.x.y\php.exe

Here x and y are the version numbers of PHP that have been installed

Open the terminal from there or navigate to there using the cd command

Then simply do:

php your_script.php

Using VB.NET this would give something like:

Process.Start(String.Format("cmd /k {0} & {1}", "cd c:\wamp\bin\php\php5.x.y\php.exe", "php your_script.php"))
Mederic
  • 1,752
  • 3
  • 17
  • 31