简体   繁体   English

使用PHP和mysql数据库成功登录XCode后如何重定向到新视图

[英]How to redirect to new view after successful login in XCode using PHP and mysql database

I have a project which is an Ipad application. 我有一个项目是Ipad应用程序。 I am using Xcode with PHP and mysql database. 我将Xcode与PHP和mysql数据库一起使用。

I have a login view, which should verify the username and password of the user by checking the database through PHP and then it should move the user to his profile view. 我有一个登录视图,该视图应通过通过PHP检查数据库来验证用户的用户名和密码,然后将用户移至其个人资料视图。

in PHP, I know that the statement: ex.( header ("Location: profile.php") ) will move the user to the page (profile.php). 在PHP中,我知道语句:ex。(header(“ Location:profile.php”))会将用户移至页面(profile.php)。

my questions are: 我的问题是:

which statement do I have to use to move from one view to another using php and xcode, instead of moving to a php page? 使用php和xcode从一个视图移动到另一个视图,而不是移动到php页面时,我必须使用哪一条语句? how to make a session for my login code? 如何为我的登录代码进行会话?

here is my PHP code: 这是我的PHP代码:

<?php

//Getting entered values
$username = $_GET['name'];
$password = $_GET['pass'];

//database info 
$DB_HostName = "localhost";
$DB_Name = "test";
$DB_User = "root";
$DB_Pass = "";
$DB_Table = "user";

//connecting to database
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass);
mysql_select_db("$DB_Name");


//Create query
$qry="SELECT * FROM user WHERE name='$username' AND pass='$password' ";
$result=mysql_query($qry);



while($row= mysql_fetch_array($result)){

if($row['pass']== $password){
echo $row['name'];
}else{
echo'error';
}

?>

here is my objective c code: 这是我的目标C代码:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)enterCredential{

    NSMutableString *mtURL = [[NSMutableString alloc] initWithFormat:@"http://localhost     /login.php?name=%@&pass=%@",username.text ,password.text];


    [mtURL setString:[mtURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSData * dataUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:mtURL]];
    NSMutableString * mtResult = [[NSMutableString alloc] initWithData:dataUrl encoding:NSUTF8StringEncoding];
    NSLog(@"PHP fatmah %@", mtResult);
}

@end

which statement do I have to use to move from one view to another using php and xcode, instead of moving to a php page? 使用php和xcode从一个视图移动到另一个视图,而不是移动到php页面时,我必须使用哪一条语句?

In Objective C you do that by performing a segue from one controller to the other read up on the function performSegueWithIdentifier:sender: 在Objective C中,您可以通过从一个控制器执行到另一个控制器的segue读取功能performSegueWithIdentifier:sender:

how to make a session for my login code? 如何为我的登录代码进行会话?

You can set a flag from your php that will determine wether the login is valid or not. 您可以从您的php设置一个标志,该标志将确定登录是否有效。 If authenticated you can use NSUserDefaults to store the values you need. 如果通过身份验证,则可以使用NSUserDefaults存储所需的值。 That flag could be a boolean that you send from your php script to your iPad app. 该标志可能是您从php脚本发送到iPad应用程序的布尔值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM