简体   繁体   中英

Calling client side application using server side language PHP

I am trying to create an application for client side that can be called by php and terminates certain program when it executes. I tried developing an exe file for this but I can't call the exe file via php on client side. Is there any other format of application I can develop that can be called by php? Can I develop a windows service and call it via php instead? I can ask users to download and install anything. However I cannot use javascript to achieve this.

I'm going to rephrase your question slightly to make sure I understand:

Can I use PHP script on a server to call an EXE on user's (client) computer?

If that is your question then the answer is:

No. There are other methods, but they generally will not work outside a very strict subset of authorized websites and clients or specialty cases.

However, you state in your question I can ask users to download and install anything. If the user can download a file (executable) from your website and then run it on their computer, what seems to be the problem?

I managed to solve this problem but I'm not sure how applicable it is for anyone else who might ever face this problem.

I set up a cookie in php and I check for the value of that cookie in the client's computer.

In my case I'm forcing the clients to use XULRunner as their browser client so there is only one location for the cookie to exist. In case the browser is not fixed, all locations for all browsers need to be handled separately.

Following is the code I am using for the application in client's computer:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace beforeSEBstart
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a timer that polls once every 5 seconds
            string appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            Console.WriteLine(appdata);
            string curFile = appdata+@"\ETH Zuerich\xul_seb\Profiles\cookies.sqlite-wal";
            System.IO.File.WriteAllText(curFile, string.Empty);
            var timer = new System.Threading.Timer(TimerProc, null, 5000, 5000);
            Console.WriteLine("Polling every 5 seconds.");
            Console.WriteLine("Press Enter when done:");
            Console.ReadLine();
            timer.Dispose();
        }

        static int TickCount = 0;
        static void TimerProc(object state)
        {
            ++TickCount;
            Boolean found = false;
            Console.WriteLine("tick {0}", TickCount);
            string appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            Console.WriteLine(appdata);
            string curFile = appdata + @"\ETH Zuerich\xul_seb\Profiles\cookies.sqlite-wal";
            string line;
            Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
            //Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
            Stream stream = File.Open(curFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader file = new StreamReader(stream);
            while ((line = file.ReadLine()) != null)
            {
                if (line.Contains("SEBClose2"))
                {
                    found = true;
                }
            }
            if (found)
            {
                Console.WriteLine("String exists in the file.");
                System.Diagnostics.Process.Start("ConsoleApplication1.exe");
                foreach (System.Diagnostics.Process myProc in System.Diagnostics.Process.GetProcesses())
                {
                    if (myProc.ProcessName == "beforeSEBstart.vshost" || myProc.ProcessName == "beforeSEBstart")
                    {
                        myProc.Kill();
                    }
                };
            }
            else
            {
                Console.WriteLine("String does not exist in the file.");
            }
            file.Close();
        }
    }
}

For server side, I just set up a cookie named SEBclose2 in php when client presses the exit button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM