开发者

Easy HTTPS to PHP script

here is my scenario:

I have a website with php, mySQL. I have a software application that has a login screen and sends usernames and passwords over the web by http:

    public String GetWebPage开发者_如何学GoSource(String pURL)
    {

        try
        {


            byte[] vReceivedBytes = null;
            using (System.Net.WebClient vWebClient = new System.Net.WebClient())
            {
                vReceivedBytes = vWebClient.DownloadData(pURL);
            }
            int vBomLen = 3;
            byte[] vStrippedBytes = new byte[vReceivedBytes.Length - vBomLen];
            Array.Copy(vReceivedBytes, vBomLen, vStrippedBytes, 0, vReceivedBytes.Length - vBomLen);

            return System.Text.Encoding.UTF8.GetString(vStrippedBytes);



        }
        catch (Exception e)
        {

            Console.WriteLine(e.Message);
            return null;
        }

    }

So to send a username and password I would write:

GetWebPageSource("http://mywebsite.com/Login.php?username=stackoverflow&password=iscool")

and the php file would spit out some text saying whether the password is accepted or denied.

However this is NOT secure. So I want to make it secure... https. How easy is it to integrate https? How much will the code change? How much do I have to handle? What is transparent to me. Do I have to check if a cookie already exists and if not write the methods for authentication or is there librarys already provided that will do it for me?


For programming point of view, calling an php script using http or https doesn't make any difference. It's just a matter of configuring apache (or any other web server) to handle https (most notably obtaining a certificate).


In a nutshell, you'll want to configure the web server to use TLS/SSL. It doesn't really matter which server-side language you're using for your site.

In general, the server side scripts will set a cookie/session on successful authentication, and then just check the cookie or session data for any actions that require an authenticated user. With a properly configured server, the encryption of the authentication is handled automatically by the server and the client's browser.

I also recommend using a debugging proxy and watching the requests/responses to and from the server during the authentication steps. This'll show you whether or not you actually have a secure connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜