通过'&';在从xcode到php的字符串中?

通过'&';在从xcode到php的字符串中?,php,ios,objective-c,xcode,Php,Ios,Objective C,Xcode,我正在用iphone中的webservice编程,它可以访问mysql数据库,该数据库包含“移动和游戏解决方案”之类的值。我从用户那里获取这个字符串值,并将其传递到php文件。但是php不接受带“&”的字符串。它只接受“移动”。帮助我。我在xcode中的代码是: strEditbuunit = [labeditbunit.text stringByReplacingOccurrencesOfString:@" " withString:@"+"]; NSString *Updpost =[NS

我正在用iphone中的webservice编程,它可以访问mysql数据库,该数据库包含“移动和游戏解决方案”之类的值。我从用户那里获取这个字符串值,并将其传递到php文件。但是php不接受带“&”的字符串。它只接受“移动”。帮助我。我在xcode中的代码是:

strEditbuunit = [labeditbunit.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];

NSString *Updpost =[NSString stringWithFormat:@"buname=%@",strEditbuunit];

UpdLTRhostStr = @"http://localhost/practice/ltrupdate.php?";

UpdLTRhostStr = [UpdLTRhostStr stringByAppendingString:Updpost];  
UpdLTRdataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:UpdLTRhostStr]];
UpdLTRserverOutput = [[NSString alloc] initWithData:UpdLTRdataURL encoding: NSASCIIStringEncoding];


<?php
$con = mysql_connect("192.168.0.82","android","android");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("androidlogin", $con);
$buname = $_GET["buname"];
$retval1 = mysql_query( "SELECT code_id FROM typedescs where name = '$buname'" );
    while($row1 = mysql_fetch_assoc($retval1))
    {
        $bu_id = $row1['code_id'];

    }
 echo $buname;
mysql_close($con);
?> 
strEditbuunit=[labeditbunit.text stringByReplacingOccurrencesOfString:@''带字符串:@“+”];
NSString*Updpost=[NSString stringWithFormat:@“buname=%@”,strEditbuunit];
UpdLTRhostStr=@”http://localhost/practice/ltrupdate.php?";
UpdLTRhostStr=[UpdLTRhostStr stringByAppendingString:Updpost];
UpdLTRdataURL=[NSData datawithcontentsofull:[NSURL URLWithString:UpdLTRhostStr]];
UpdLTRserverOutput=[[NSString alloc]initWithData:UpdLTRdataURL编码:NSASCIIStringEncoding];

它与PHP无关。您没有在URL中引用查询参数

UpdLTRhostStr = @"http://localhost/practice/ltrupdate.php?";
UpdLTRhostStr = [UpdLTRhostStr stringByAppendingString:Updpost];  
这里有一种方法:

UpdLTRhostStr = [NSString
    stringWithFormat:@"http://localhost/practice/ltrupdate.php?buname=%@",
    CFURLCreateStringByAddingPercentEscapes(
        kCFAllocatorDefault, (CFStringRef) buunit, NULL,
        CFSTR(":/?#[]@!$&’()*+,;="), kCFStringEncodingUTF8)];

不要忘记,在将字符串传递给MySQL之前,还需要在PHP端转义该字符串。正如Marc B所指出的,你有一个严重的安全漏洞。

不错。享受您的服务器pwn3d。如何做。请给我一些例子。@user2210195:例如,如果您有
&
,它将被替换为
%26
。其他特殊字符也会以同样的方式被替换;在php方面。它是对的。它不起作用。我也是php新手。plz帮助“它不起作用”不够具体。你需要告诉我们实际发生了什么,以及你预期会发生什么。