He’s talking about an application… e.g. an .exe file you download an run from your desktop environment… i believe.
Anyway, yes, you need to setup a php script that runs the commands, then use some webconnector to fetch the data and then you may use it within your program
Ok, so I will need to prepare a PHP script that can return the MySQL data from the database to my application. In other words, I will call the PHP script from my visual studio application which will return the data to my application and my application will display it. Am I right?
Getting the data returned by a PHP page is the best way to do this - connecting to the database directly from your program will surely create some security flaws, because you’re providing the username/password. (C# is compiled to byte code so the program can be reverted back to source code)
However, this is how I would to this: send the data from your program to the webpage using POST/GET method and retrieve the page’s source - and check if the response is what you want.
If you can’t find useful information on Google, I wrote an article that explains how to do this, by using WebClient.
This is a great tactic as well, however this presents its own set of flaws, if the C# is decompiled and it the user notices how it is one he could spoof that, the safest way to do this would be sending the hash for evaluation. However if this is a private program going to only a few people you could always do a mac address filter or IP filter along with it.
*All your website files should be into public_html.
@snowizgr8 : a hash would be good, but will not be 100% safe - if someone decompiles the program and finds the salt, he can bruteforce the hash.
But…this will take him some time
I don’t actually know what kind of data is sent to the page.
@snowizgr8: nothing is safe - but most of the times, those methods will discourage people from trying to crack the program.
Well, let’s keep it simple for the moment - there’s actually no need to involve security measures now - it will only make the project more complicated and harder to understand.
@JBOY: if there are any problems, feel free to ask.
Thank you guys for your help and insight but I am still facing issues, when I run the below code, I see some web page information printed in the console not the things from my php script, so it means it is not communicating. My c# code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string requestMethod = “POST”;
string postData = “var1=Hello&var2=Server!”;
I have another question, is it ok if I try to learn to use web services to pass the data from my c# app to the PHP script which grabs the data and insert them into the MySQL database?
It’s ok to do this, but you’ll need additional security - someone might exploit this by sending corrupted data to the php page, that can harm your database (Sql Injection). If you really need to do this, try sanitizing the input data first (remove any character that can modify your MySql query).
I don’t really have to do this, but I am just trying to find out the best way to approach this, it seems that POST/GET is the common and safest way to use.
Question about the files in the web server host, right now, I am putting every PHP script inside the public_html folder but this is not right since anyone can view these files by going to my website. So where do I put the files so that I am the only one who can see them by logging in and I can still use them.
For example, if I try to run the dataRequest.php from my c# app, I want to put the dataRequest.php in some directory apart from the public_html. I am not sure where to put it.