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条)

报告相同问题?

悬赏问题

  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。