简体   繁体   English

使用远程php脚本将mysqli_query()发送到Intranet

[英]Send a mysqli_query() to an intranet with a remote php-script

currently, I am programming an Android app that connects to a php-server. 当前,我正在编程一个连接到php服务器的Android应用。 On that server are some php-scripts, which send mysqli_queries and receive responses of remote mysql databases. 在该服务器上有一些php脚本,它们发送mysqli_queries并接收远程mysql数据库的响应。

<?php
    error_reporting(0);
    $db_host = $_POST["dbhost"];
    $db_uid = $_POST["dbusername"];
    $db_pass = $_POST["dbpassword"];
    $db_name = $_POST["dbname"];

    if ($db_host == "" || $db_uid == "" ||  $db_pass == "" || $db_name =="" ) 
        echo "Missing information!";
    else
    {
        $con = mysqli_connect($db_host,$db_uid, $db_pass, $db_name);
        // Check connection
        if (mysqli_connect_error())
            die("Couldn't connect to the database!");
        else
            echo "Connection Successfull";
    }
?>

That works without any problems, but now, I need to connect to an intranet first, to get access on a local database. 这样做没有任何问题,但是现在,我需要先连接到Intranet,才能访问本地数据库。

I thought about a php-script that connects to the intranet (via vpn) and if the connection is established it runs the mysql queries. 我想到了一个通过vpn连接到Intranet的php脚本,如果建立了连接,它将运行mysql查询。 After the php-script received the response it disconnects and sends the result back to the Android app. 在php-script收到响应后,它将断开连接并将结果发送回Android应用程序。 Sadly I've never done that before and Google seems to not know an answer. 可悲的是,我从未做过,Google似乎不知道答案。

I don't want that the whole server connects to the intranet itself, just the scripts are allowed to establish a connection, because other mysqli_queries are executed at the same time. 我不希望整个服务器都连接到Intranet本身,只允许脚本建立连接,因为其他mysqli_queries是同时执行的。

My question, is that possible? 我的问题,可能吗? And if it isn't, is there another solution how to solve my problem? 如果不是,是否还有另一种解决方案来解决我的问题?

Thank you pretty much in advance. 提前非常感谢您。

The best solution is that you created a web service on your intranet and you consume it from your android device you can enviyer gives them the get method of utl web service. 最好的解决方案是,您在Intranet上创建了一个Web服务,然后从Android设备上使用了该服务,您可以让他们为他们提供utl Web服务的get方法。 For the augulenter securiter your web service you can add a variable that you patage between the web service and the android application. 对于给您的Web服务提供安全性的用户,您可以在Web服务和android应用程序之间添加一个分页的变量。

To solve this you have to setup a specific port that will communicate outside or an api and secure it via a public key. 为了解决这个问题,您必须设置一个将与外部或api进行通信的特定端口,并通过公共密钥对其进行保护。 More exactly you can just forward a port what can work on http from the server in your intranet. 更准确地说,您只需转发一个端口即可在Intranet中的服务器上运行HTTP。 Something like http://address:8888 and pull data through an API . 诸如http:// address:8888之类的东西,并通过API提取数据。 That's the most secure way. 那是最安全的方法。 Please take this answer into account only if you feel that I understood correctly. 仅当您认为我理解正确时,才考虑此答案。 If now add a comment and I can still give you some ideas. 如果现在添加评论,我仍然可以给您一些想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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