ios+php Register Login System tutorial PHP section (top)

Source: Internet
Author: User

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.

<?php
$DBHOST = "localhost";
$DBUSER = "root";
$DBPWD = "";
$DBNAME = "Ioslogin";
?>
Then create the primary file index.php.
[PHP] View plaincopy
<?php
Header ("Content-type:text/html;charset=utf-8");
Require_once "config.php";
Connecting to a database
$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 '];
Switch ($action) {
Case "Login":
$STR = "SELECT * from Users where user_name= ' $user _name ' and user_pwd= ' $user _pwd '";
$result = mysql_query ($str, $connection);
@ $rows = mysql_num_rows ($result);
if ($rows) {
$loginFlag = "1"; Login successful
}
else{
$loginFlag = "0"; Login failed
}
$RETURNARR =array ("Loginflag" => $loginFlag);
Echojson_encode ($RETURNARR); Output JSON format
Break
Case "Regist":
$str = "INSERT into users (user_name,user_pwd) VALUES (' $user _name ', ' $user _pwd ')";
$result = mysql_query ($str, $connection);
if ($result) {
$registFlag = "1";//Registration successful
}
else{
$registFlag = "0";//Registration failed
}
$RETURNARR =array ("Registflag" => $registFlag);
Echojson_encode ($RETURNARR);
Break
Default
echo "Login mode error";
Returnfalse;
Break
}
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.

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.