Solved

How PHP Script Send results to a Desktop Program ?

Posted on 2004-10-03
18
307 Views
Last Modified: 2012-06-21
Hello ,

i design a program using C# (as Desktop Based Program)  and PHP (Web Based Program)

the idea of the program is as following :

the user have the Application in his machine ( .EXE Application ) , and when he run the program , he have to enter the user name and the password , then the Application will send these information to .PHP File on the website ,

the PHP File will check for the validity of this information in the DB , and will respond by yes or no (correct or not correct) !

My Question is : how can i respond the answer to an application on the user machine using PHP ,

in another word , what should i use to send the information from the webserver applications (PHP Application) , to User Machine application (Windows Application -.EXE- )

Note : i need to send the results in XML File to be will structured , how can i do it

Thanks ,
0
Comment
Question by:BinaryTree
18 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
I guess you just have to store information in an specific page, so, call the PHP page, generate the XML file, an optionally  return the page address in the generated page by PHP.
0
 

Author Comment

by:BinaryTree
Comment Utility
Hello jaime ,

ok , when a request is sent to the php page from Windows Application (For example : login.php?username=hi&password=hi)  

i want the PHP Application to respond to the client who use the Windows Application with yes or no , exactly like MSN Messenger , when you try to logged in incorrectly , you will get a message from the server to your application to let you know that you enter wrong informations !!

i want to use XML File to exchange the data from my Windows Application to PHP Application and vice versa ! or any other technology , it is not very important to use XML but i think it is the best way ?

how can i solve this problem ?

0
 
LVL 4

Expert Comment

by:Skonen
Comment Utility
I'm not to familiar with C#, but in all the other Microsoft influenced languages like C/C++, you can simply connect to the pages address login.php?username=hi&password=hi and read the content returned. I don't think it can get any simpler than that.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
I agree with Skonen, just have to read returning html code generated by PHP. As I mentioned, when calling the login or any other query page, just have to read the returning page text.

But, why not to do all in PHP? I think could be easier and cleaner.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
If you are working with .NET Platform and want to exchange XML information, then I recommend you to learn about SOAP:
http://www.codeproject.com/soap/laymansoap.asp
http://www.codeproject.com/soap/bubbly.asp
http://www.codeproject.com/soap
0
 

Author Comment

by:BinaryTree
Comment Utility
Hello ,

I think i did not describe my problem will !!


Imagine the following scence :

1- You open your MSN Messenger

2- You enter your username and password incorrectly

3- your Messenger Application send the information to the server (that is use .aspx files for example)

4- the server do checking with your information , then it will find that the user name or password is not correct !

5-the server (.aspx file) send a message to your machine with error number and a string that describe the error

6-Your Messenger (that is exist in your machine) receive the message (in XML Structure or whatever) and display it with Windows Form Dialog Box !


my problem exist in Step # 5 , how can i do this thing (but in PHP)


i hope that it is clear now :)

Thanks all

0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
PHP produces HTML pages, most based in arguments passed in address or through an HTML form. The result is an HTML page, whatever you want.
As you mentioned you use C# in your client side, you have only to invoke a PHP page and read the results, result could be a pure HTML file, or with XML info inside, this doesn't matter.
Then your problem is reduced to **PARSE** HTML 'source code' returned by PHP page.

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 400 total points
Comment Utility
0
 

Author Comment

by:BinaryTree
Comment Utility
Dear  jaime_olivares ,

this way is not too much Efficient  , because there is problems of Synchronization

imagine if the server is a little bit lagged , so generating this HTML Page will take time (maybe several second) , so the client application will try to read the HTML file that is still not exist because it is not generated yet by the Server !!

also there is a very secret information that i want to send it from the server to the client direct , so i can not put this information in HTML Files in the server , any begginer hacker can access to these file (Because it is plain HTML Files saved in known non - secure )directory ) !!

i read alot about XML-RPC and SOAP in PHP , is these technology can solve my problem , and how ( all the examples that i read in XML-RPC and SOAP , use PHP as the Client and Server Applications , i did not read any example show that it is possible to communicate between diffrent Platforms using diffrent Programming Languages ! )



Thanks ,



0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
>this way is not too much Efficient  , because there is problems of Synchronization
>imagine if the server is a little bit lagged , so generating this HTML Page will take time (maybe several second) , so the client
> application will try to read the HTML file that is still not exist because it is not generated yet by the Server !!
No synchronization error possible, because the client application will wait up to page completion and inform you by any flag or callback function.

>also there is a very secret information that i want to send it from the server to the client direct , so i can not put this
> information in HTML Files in the server , any begginer hacker can access to these file (Because it is plain HTML Files saved
> in known non - secure )directory ) !!
This is the same problem in HTML, XML or whatever, just have to CYPHER your data first, or to use a secure protocol like SSL.

> i did not read any example show that it is possible to communicate between diffrent Platforms using diffrent Programming Languages !
Of course you can, in you can communicate with ANY programming language's application through the Internet, with the appropiate format.

 
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
I have posted you many links for SOAP clients, it is not important who is the server (PHP, ASP, etc.)
0
 

Author Comment

by:BinaryTree
Comment Utility
Dear jaime_olivares , Thanks for your interesting ,,

you said : " No synchronization error possible, because the client application will wait up to page completion and inform you by any flag or callback function. "

now that is the point , if i can inform the client about the page completion by a flag or a callback function , then i can send an information back to the client directly and that is what i want ... i need the PHP Script to send an information to the Client Program (which is in our case is Windows-Based Application )

i real alot about SOAP , and XML-RPC in PHP , but i see that in all examples the client and the server is a PHP Scripts . what should i change to let the client is Windows Based Application and the server is PHP Application or vice versa ..

for example , the following code is SOAP Client Creating in PHP .. :

$soapclient= new soapclient('http://localhost/soap_server.php') ;


in my case , the receiver of the information is not a PHP Script , it is a windows based application , so can i put the IP Address of the machine that is run the Application instead of 'http://localhost/soap_server.php'  ??? if not what can i do then to send the information to the Windows Based Application from Web Based Application (PHP Application)


Thanks alot :)

0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
>... i need the PHP Script to send an information to the Client Program
Please understand me, you don't have a script to SEND info, just write an HTML page as usual, your client software just have to parse this result page.

> but i see that in all examples the client and the server is a PHP Scripts
Here are examples of SOAP clients with Visual C++, no matters if SOAP server is PHP or any other:
http://www.codeproject.com/soap/vcrope.asp
http://www.codeproject.com/soap/calc_eg.asp
http://www.codeproject.com/soap/VSOAPClient.asp

>in my case , the receiver of the information is not a PHP Script , it is a windows based application , so can i put the IP
> Address of the machine that is run the Application instead of 'http://localhost/soap_server.php'  ??? if not what can i do then
 >to send the information to the Windows Based Application from Web Based Application (PHP Application)
You don't need the IP or name of client application, just fill HTML page as usual (or maybe a TXT or a XML page, doesn't makes difference)


0
 

Author Comment

by:BinaryTree
Comment Utility
Hello jaime_olivares

I know that i can get the result as HTML or XML by parsing the result of the requested page , for example if i call this page :

login.php?username=xxx & password=yyy

then the requested page will generate a HTML Code that i can read it from my windows based program and then i can parse it to get the result ...

I know that i can follow this method , but i need to know how can i use SOAP or XML-RPC with to diffrent Programming Languages , one is PHP , and the other is C#

from the side of the C# Program i have no problems because i just have to listen and wait for the information and i didnt send any thing

but from PHP Side , i have to send the information (or call a remote procedure)  , i see that all examples put  a Path to PHP script that will receive the information like the following code :


soapclient('http://localhost/soap_server.php') ;  

what if my receiver of this information (or the program that i will cal its function ) is not PHP Application , it is C# Application located in a machine that is connected to the web , is it as simple as replacing the URL in 'soapclient' function by IP address of the one who is connected to the web and call the Login Page !!!!!!!!

that is all what i want to know

Thanks :)



0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
>what if my receiver of this information (or the program that i will cal its function ) is not PHP Application , it is C# Application
> located in a machine that is connected to the web , is it as simple as replacing the URL in 'soapclient' function by IP address
> of the one who is connected to the web and call the Login Page !!!!!!!!
The message in soap is an XML files, then NO MATTERS which language is sender and which receiver, just matters that both will handle a XML file. THAT'S THE BEAUTY OF SOAP!!!!
About using an URL or an IP address, doesn't matters too.

0
 

Author Comment

by:BinaryTree
Comment Utility
Hello  jaime_olivares

Ok , that is mean if i replace the URL in the soapclient function by IP i will get a valid result .


notice that the URL is the location for specific file , but the IP is the address for a whole machine , i did not specify the port , and i did not specify the exact program that i want to talk with !!!!


Thanks

0
 
LVL 5

Assisted Solution

by:basiclife
basiclife earned 100 total points
Comment Utility
Ok, I may be coming at this from the wrong side but...

PHP script: http://www.yourserver.com/login.php

Pass it un/password ie use C# to access the page http://www.yourserver.com/login.php?un=username&pass=password

<?php
//login.php
if($_GET['un'] = "test" && $_GET['pass'] = "test2") {
    print "OK";
} else {
    print "Failed";
}
?>

obviously you need to update the if() statement to check with the database you have

When c# loads the page (passing the username/pass in the URL) it'll eaither see "OK" or "Failed" which it can the use to pop up a "your login has failed" box or anything else.

The point is, PHP doesn't know (or care) what sort of software it's talking to. Anyone else seeing the page from on the internet will only see "Failed" (unless they guess a correct username/password).

You can make this a bit more secure by using SSL / some other encryption on the connection so nobody can see the password on the way out but the principle holds true.

This is less a PHP question and more a C# question. All you need to do is read the specified page into C# (which I know ery little about, so I can't help there).

As to IP address / port / etc... DNS lookups should happen in the background to work out the IP address from the host name and the port will be 80 as you're talking to a web server.

C# Pseudo-Code:
=========================
checklogin = Open URL (http://www.yourserver.com/login.php?un=test&pass=test2)
if checklogin = "OK"
        allow client to continue
else
        tell client login failed
endif
=========================

The Open URL function should wait until the page has downloaded before allowing the script to continue so there's no need to open ports / connections to scripts.
0
 

Author Comment

by:BinaryTree
Comment Utility
Actually no one Know what i am talking about , i am talking about Web Services , which let the server excute Procedures in the client side , by using SOAP or XML-RPC ... and my Question was how to let the PHP Script talk directly to C# Application in the client machine and excute procedure on it ( on the client machine that use the c# application) , for sure in this case i have to use SOAP or XML-RPC , but i did not find any article or tutorial that show how to do this kind of interaction (From PHP To Win32 Application in the user machine )


Any way , i will try to ask my question in another Forum , thanks you all

and i will Split the points between jaime_olivares &  basiclife  

Thank you
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now