Simple server program written in PHP scripting language

Source: Internet
Author: User
Tags php script

<?php
$username = $_post["username"];/* client request mode is POST, request parameters encapsulated into NSData type in httpbody to the server, the server in the PHP script language to receive the request parameters, Find data in the server based on parameters returned to the client */
$password = $_post["password"];
$type = $_post["type"];

/* Link Database 127.0.0.1 is loopback address, network software test, and Local machine interprocess communication */
$link = mysql_connect ("127.0.0.1", "root", "Nilaiba");/* Establish database connection (host address, user name, password) */
if ($link) {/* If database connection Cheng ' gong*/
/* Select the specified database */
if (mysql_select_db ("Duke", $link)) {
/* Define an array, save the results */
$results = Array ();
if ($type = = "Login") {
$selecSQL = "Select password from UserInfo where user_name = ' $username '";
$result = mysql_query ($selecSQL);
$row = Mysql_fetch_array ($result);
if ($row ["password"] = = $password) {
$results ["status"] = "success";
} else {
$results ["status"] = "Failed";
}
Echo (Json_encode ($results));//data returned by the server to the client
} else {
$insertSQL = "INSERT into userInfo values (' $username ', ' $password ')";
$result = mysql_query ($insertSQL);
$row = Mysql_fetch_array ($result);
Echo (Json_encode ($row));//data returned by the server to the client
}
}
}
?>

Simple server program written in PHP scripting language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.