Finally achieve the effect:
Analyze the basic process of doing the project:
1. Create a database First
2. Write PHP server
3. Write iOS user side
1. Create a database
I'm using a wamp.
The database name is Ioslogin, and the table named users has 3 fields User_id,user_name and user_pwd.
USER_ID for self growth.
2.php Service End
PHP side I use is eclipsephp writing.
First create a configuration file config.php.
Then create the primary file index.php.
Header ("Content-type:text/html;charset=utf-8");
Require_once "config.php";
$connection = mysql_connect ($DBHOST, $DBUSER, $DBPWD);
$db _selecct= mysql_select_db ($DBNAME);
$action =$_get[' action ']; To differentiate between login and registration
$user _name=$_get[' user_name ']; Get method is convenient for debugging
$user _pwd=$_get[' user_pwd '];
$STR = "SELECT * from Users where user_name= ' $user _name ' and user_pwd= ' $user _pwd '";
$result = mysql_query ($str, $connection);
@ $rows = mysql_num_rows ($result);
$loginFlag = "1"; Login successful
$loginFlag = "0"; Login failed
$RETURNARR =array ("Loginflag" => $loginFlag);
Echojson_encode ($RETURNARR); Output JSON format
$str = "INSERT into users (user_name,user_pwd) VALUES (' $user _name ', ' $user _pwd ')";
$result = mysql_query ($str, $connection);
$registFlag = "1";//Registration successful
$registFlag = "0";//Registration failed
$RETURNARR =array ("Registflag" => $registFlag);
Echojson_encode ($RETURNARR);
Mysql_close ($connection);
|
Write here students can test PHP first to see if there are errors.
You can add a piece of data to the database first.
And then enter Localhost/ioslogin/index.php?action=login&user_name=admin&user_pwd=admin in the browser.
Where Ioslogin is the name of the PHP project, and output JSON is almost right.