最后达成效果:
分析做项目的基本流程:
1.先创建数据库
2.写php服务端
3.写ios用户端
1.创建数据库
我用的是wamp。
数据库名称为ioslogin,表名为users其中有3个字段user_id,user_name和user_pwd。
user_id为自增长。
2.php服务端
php端我用的是eclipsephp编写。
先创建一个配置文件config.php。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<?php
$dbhost = "localhost" ;
$dbuser = "root" ;
$dbpwd = "" ;
$dbname = "ioslogin" ;
?>
然后创建主要文件 index.php。
[php] view plain copy
<?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 );
$user_name = $_get [ 'user_name' ]; //get方法方便用于调试
$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" ; //登录成功
}
else {
$loginflag = "0" ; //登录失败
}
$returnarr = array ( "loginflag" => $loginflag );
echo json_encode( $returnarr ); //输出json格式
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" ; //注册成功
}
else {
$registflag = "0" ; //注册失败
}
$returnarr = array ( "registflag" => $registflag );
echo json_encode( $returnarr );
break ;
default :
echo "登录方式错误" ;
return false;
break ;
}
mysql_close( $connection );
?>
|
写到这里 同学们可以先对php进行测试看看有没有错误。
可以先在数据库里加一条数据。
然后在浏览器里输入localhost/ioslogin/index.php?action=login&user_name=admin&user_pwd=admin
其中ioslogin是php项目名称,有输出json就差不多是正确的。
ios+php 注册登录系统(二) ios部分
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。