dongqian6554 2016-08-03 04:19
浏览 55
已采纳

如何在一个在线服务器上运行php程序

I have some php files that freely run on my online PHP,MySQL server. As an example if it concern about addUser.php (here is that code)

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){

$name = $_POST['name'];
$email = $_POST['email'];
...

$sql = "INSERT INTO users (name,email,...) VALUES ('$name','$email',...)";

require_once('DbConnect.php');

if(mysqli_query($con,$sql)){
        echo 'User Added Successfully';
 }else{
       echo 'Could Not Add User';
 }

 mysqli_close($con);
 }

I have coded my ANDROID Application to access this type of php file by StringRequest using URL

http://www.***.com/addUser.php

and pass the parameters using HashMaps

So, I want to know how is this php file runs when android user access it, and what will occur when thousands of android users started accessing this php file and started to insert data into my online server Database concurrently. And if there is a problem occur what is the solution for it?

I just want to know is it a problem occur when many users try the same php file at same time?? I mean we use synchronizing in multi-threading to prevent occuring a problem when many users use the same at sametime. As in that way is there will a problem occur when thousands of users adding data through this php file

  • 写回答

2条回答 默认 最新

  • 普通网友 2016-08-03 04:35
    关注

    Lets assume you're going to keep using this script.

    1. You must stop duplicate emails being inserted

    Run a select * from users where email = '$email' before inserting the user. If the results.length == 0, insert the user, if not return an error.

    1. Validate the incoming POST data

    Here you should do some basic validation:

    $name = $_POST['name'];
    $email = $_POST['email'];
    // Do some checks here which will validate the email
    

    See the following page for a more in depth look into validating:

    http://php.net/manual/en/filter.examples.validation.php

    Other than that there are some floors

    1. You should make users use a password
      • The password should also be hashed
    2. SQL injection

    One more thing, maybe have a look at other examples. E.g

    http://www.tutorialspoint.com/php/php_login_example.htm

    Edit:

    Seems like you want to implement a google login (based on your comment).

    Here's how I'd do it:

    1. On the client (app), the user would login to there google acc.
    2. In return we would get there accountId and an OAUTH token
    3. We would then send the token + OAUTH token to our PHP server.
    4. The php server would then use a google php library to validate the OAUTH token that we retrieved from the client.
    5. The library would then return information on that user including there google id and other relevant information that was requested.
    6. Check to see if the user has an account by cross checking the google id returned against our database.
      • Select * from dbTABLENAME where googleId =
    7. IF there was nothing returned in step 6, we would then store the googleId + other information (email) in our own database, IF THERE WAS something returned in step 6, we'd return some sort of token to the client that would be used to validate all other requests

    This link will help ->

    http://phppot.com/php/php-google-oauth-login/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么