我怎样才能连接到通过JavaScript在我的PHP程序装在一个服务器? [英] How can I connect to a server through JavaScript where my PHP program is housed?

查看:190
本文介绍了我怎样才能连接到通过JavaScript在我的PHP程序装在一个服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序,并且已经写在HTML和PHP工作计划。利用两个,它们接触的API与html页面上的用户定制查找,然后发送到PHP页面,接触与所述定制的搜索该API,得到的结果,并且在PHP输出到HTML网页试。

I am writing an Android App, and already have a working program written in HTML and PHP. Using the two, they contact an API with a user customized lookup on the html page, which then sends to the PHP page, contacts the API with the customized search, gets a result, and the php outputs to a html page again.

我知道PHP不能在Android上工作,但我打算使用PhoneGap的。随着PhoneGap的,我可以运行JavaScript,HTML和CSS据说。我也看到了与Android是无法理解PHP的解决方案是连接到服务器(我的电脑),它可以运行PHP的我,然后把它输出的方式在手机上可以理解。

I know PHP cannot work on Android, but I plan on using PhoneGap. With PhoneGap, I can run JavaScript, HTML, and CSS supposedly. I have also read that a solution with Android being unable to understand PHP is to connect to a server (my computer) which can run the php for me, and then output it in a way the phone can understand.

我的计划是使用JavaScript,它的PhoneGap可以理解,连接到我的电脑,并以HTML它再次运行PHP输出的页面,PhoneGap的可以理解。

My plan is to use JavaScript, which PhoneGap can understand, to connect to my computer, and have it run the PHP and output the page in HTML which again, PhoneGap can understand.

如果这是荒谬的,请让我知道......否则,我会非常AP preciate,如果有人可以把我在正确的方向中的JavaScript函数,让我对自己进行身份验证,连接到我电脑,并告诉它我想使用一个特定的PHP文件。

If this is absurd, please let me know... Otherwise I'd greatly appreciate it if someone could push me in the right direction in a JavaScript function that would allow me to authenticate myself, connect to my computer, and tell it I'd like to use a certain PHP file.

推荐答案

我们开发我们的应用程序为Android和iOS版时有完全相同的问题。像奥斯汀告诉你们,你必须使用AJAX的。

We had the exact same problem when developing our application for Android as well as for iOS. Like Austin told you already you have to make use of AJAX.

W3Schools的 - AJAX

我建议你却不能使用jquery,如果它只是需要一些简单的事情,因为它是因为它加载大的脚本相当沉重。所以,如果你能减少code量,请通过学习真正的JavaScript,而不是jQuery的这么做。

I recommend you however not to use jquery if it's only needed for a few simple things because it's fairly heavy because of the big script it has to load. So if you can reduce the amount of code, please do so by learning the real JavaScript instead of jQuery.

此外,我们做的是写我们自己的APIRequest.js对象。当调用像这样这个对象:

Also, what we did is writing our own APIRequest.js object. When calling this object like so:

var result = new APIRequest('functionname', {param1:value, param2:value})

这是一个相当简单的方法来连接到你的PHP将在国外或在PC服务器上运行偏离轨道的地方。 正如你可以看到我们插入函数名,我们已经开发了API作为一个相当简单的面向对象的PHP啄,使我们能够把functionname.php在一个特定的文件夹,它会通过取消脚本读取,然后选择该功能。数据库连接之类的东西将aranged在API的指数。通过这种方法可以使特殊功能,服务器端,为每一个独特的处理方式。

This is a fairly easy approach to connect to your php which will run off course on your server somewhere in a foreign country or your pc. As you can see we insert a functionname, we have developed our API as a fairly simple OOP php thingy that allows us to put a functionname.php in a certain folder and it will be read by de script and then select that function. Database connections and stuff like that will be aranged in the index of the api. With this approach you can make special functions, server-side, for every unique handling.

我告诉你,是因为你正在使用JavaScript。我希望你明白,这是很不安全!它是安全的,因为您的计算机上的JavaScript应用程序。这是可能的黑客的apk文件下载到自己的电脑,在他的电脑模拟器中运行它,并通过他的控制台进行编辑。就这样的意思,他可以改变你的整个code(至少,JavaScript的一部分)。所以一定要尽量使这是一个安全的可能,钥匙之类的东西。另外,尽量做的逻辑是有可能你的服务器上,这样的逻辑不能改变。仅输入参数到您的API。

I am telling you this because you are making use of JavaScript. I'd like you to understand that it is not safe! It as as safe as a JavaScript application on your computer. It is possible for a hacker to download the .apk to his computer, run it in the simulator on his pc and make edits through his console. And thus meaning, he can change your whole code (at least, the JavaScript part). So make sure you try to make this as safe a possible, with keys and stuff like that. Also, try to do as much logic as possible on your server, so the logic can't be changed. Only the input parameters to your API.

我希望这有助于你!

这篇关于我怎样才能连接到通过JavaScript在我的PHP程序装在一个服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆