Php 如果语句在目标C中工作不正常
我正在创建一个需要用户输入用户名和密码的应用程序。一旦他们填写了文本字段,数据就会使用GET发送到locahost。我的php设置为,如果用户名和密码匹配,则返回值1;如果用户名和密码不匹配,则返回值2。但是如果我尝试创建这样的if语句:Php 如果语句在目标C中工作不正常,php,objective-c,xcode,if-statement,get,Php,Objective C,Xcode,If Statement,Get,我正在创建一个需要用户输入用户名和密码的应用程序。一旦他们填写了文本字段,数据就会使用GET发送到locahost。我的php设置为,如果用户名和密码匹配,则返回值1;如果用户名和密码不匹配,则返回值2。但是如果我尝试创建这样的if语句:if([received isEqualTo:@“1]”){ NSLog(“授予访问权”); }否则{ NSLog(@“访问被拒绝”); } 它返回为访问被拒绝,即使我做了一个Nslog,它返回为1,但它仍然没有说访问被授予 这是AppDelage.m: //
if([received isEqualTo:@“1]”){
NSLog(“授予访问权”);
}否则{
NSLog(@“访问被拒绝”);
}
它返回为访问被拒绝,即使我做了一个Nslog,它返回为1,但它仍然没有说访问被授予
这是AppDelage.m:
//
// AppDelegate.m
// possys
//
// Created by on 11/11/12.
// Copyright (c) 2012 . All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize username;
@synthesize password;
@synthesize super;
@synthesize alert;
@synthesize connection = _connection;
@synthesize receivedData = _receivedData;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (IBAction)login:(id)sender {
NSString *user = [username stringValue];
NSString *pass = [password stringValue];
NSString *strurl = [NSString stringWithFormat:@"http://localhost/index.php?username=%@&password=%@",user,pass];
[self.connection cancel];
//initialize new mutable data
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
//initialize url that is going to be fetched.
NSURL *url = [NSURL URLWithString:strurl];
//initialize a request from url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//initialize a connection from request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.connection = connection;
//start the connection
[connection start];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"%@" , error);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
//initialize convert the received data to string with UTF8 encoding
NSMutableString *received = [[NSMutableString alloc] initWithData:self.receivedData
encoding:NSUTF8StringEncoding];
NSLog(@"%@" , received);
if ([received isEqualTo:@"1"]) {
NSLog(@"YUPYUPYUP");
}else{
NSLog(@"YNO");
}
}
这是我的php:
<?php
mysql_connect("localhost","root","abc123") or die (mysql_error());
mysql_select_db("authentication") or die (mysql_error());
$username = $_GET['username'];
$password = $_GET['password'];
$username = stripslashes($username);
$password = stripslashes($password);
$sql = "select * from users where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die (mysql_error());
$count = mysql_num_rows($result);
if ($count == 1) {
echo "1";
}
else{
echo "2";
}
?>
假设存在某种空白问题,您可以尝试:
if([received intValue] == 1)
NSLog(@"YUPYUPYUP");
else
NSLog(@"NO");
这样,系统就可以解析文本以获得一个数字,然后比较该数字,而不是寻找精确的字符串匹配。假设存在某种空白问题,您可以尝试:
if([received intValue] == 1)
NSLog(@"YUPYUPYUP");
else
NSLog(@"NO");
这样,系统就可以解析文本以获得一个数字,然后比较数字,而不是寻找精确的字符串匹配。尝试使用isEqualToString:方法,而不是isEqualTo:
if ([received isEqualToString:@"1"]) {
NSLog(@"YUPYUPYUP");
}
else{
NSLog(@"YNO");
}
尝试使用isEqualToString:方法,而不是isEqualTo:
if ([received isEqualToString:@"1"]) {
NSLog(@"YUPYUPYUP");
}
else{
NSLog(@"YNO");
}
可能数据库中的值存储为字符串,因此如果NSLog(@“[%@]”已接收),您将获取@“1”而不是@“1”代码>这会在结果周围显示任何空白吗?条带斜杠不能防止sql注入<代码>http://example.com/?username=x&password=x或1=1--
Doif([received isEqualTo:@“1”]){NSLog(@“Access grated”);}else{NSLog(@“Access Denied--received=>>%@可能数据库中的值存储为字符串,因此如果NSLog(@“[%@]”,received),您将获取@“1”而不是@“1”)
这会在结果周围显示任何空白吗?条带斜杠不能防止sql注入。http://example.com/?username=x&password=x'或1=1;--
Doif([received isEqualTo:@“1”]){NSLog(@“Access Prograted”);}else{NSLog(@“Access Denied”-received=>%@