How can I run a PHP file from Within Visual basic

Olukayode Oluwole
Olukayode Oluwole used Ask the Experts™
I have a VB6 Application  and a PHP application on 2 different PCs

I want to take a PHP script  (attached) and run it within the Visual Basic Code

My first thought was that since the PHP Script feels like an HTML  file

there may be a  way  to run it with the Shell command

Can any one help out with this

I attach the PHP Script


O.A.  Oluwole
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Both PHP and VB are server side scripting languages.  You can't "run" a PHP file from VB.  You could convert the PHP code to VB.  Or, call the webpage that the PHP renders from VB (so that the server runs the PHP code and outputs the web page).  So, for example, launch/open http://localhost/index.php from VB

Which approach you take depends on your ultimate goal.  If you just want to display index.php, you can simply open the webpage like any other website from VB.  If you want to get results, etc that the PHP code provides and do something with them in VB, you'll need to convert the code to VB.
Ryan ChongSoftware Team Lead
Both PHP and VB are server side scripting languages.

this is somehow not true since VB6 Application is not really categorized as server side scripting languages.

To enable VB6 Application to call a html or php page, you can try:

VBA Web Requests
Most Valuable Expert 2017
Distinguished Expert 2018
A bit of misinformation going around.

PHP is a scripting language in its own right - which means if you have a PHP interpreter installed on your computer you can run a php script at the commend line like so
Script: test.php
echo "Hello World";

Open in new window

> php test.php

Open in new window

And you will get
Hello World

Open in new window

However in this case the php file provided is a web page - which means its output is going to be HTML most likely intended for a browser.

The script in question - the first thing it does is throw you to a login page because you are not logged in - so already you have a speed bump right there. For this page to do anything it
a) Needs access to a server SESSION - which you won't have when you run the file locally
b) That session needs to be primed with an empno value that will allow you to continue

So the question is really - what are you hoping to achieve here? What is it you actually want to do - because I don't think you are going to get the answer you want based on the information you have given us so far.
Fractional CTO
Distinguished Expert 2018
To expand on Julian's answer.

You can easily hand off any file to it's processor - php/perl/python/bash - have each interpreter run the code + return data via STDOUT/STDERR.

And as Julian also said, the problem occurs when you're trying to manage sessions, as your code does.

To accomplish what you're trying to accomplish, you have to reverse your logic.

You'd likely run a LAMP Stack + then call Visual Basic to perform some functions, from your LAMP Stack, so your session is maintained correctly.

And, unless you've written this type of code repeatedly, there are many subtle problems you'll requiring handling.

Likely you'll save yourself a huge amount of time using WordPress + writing your code as a WordPress (PHP) plugin.

This will also mean your code will run anywhere.

If you use Visual Basic, you're stuck with a Windows runtime environment or trying to use one of the public domain interpreters which attempts to correctly parse + execute Visual Basic.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial