2011-12-08 35 views
0

我如何传递职位数组功能,然后拉出参数,即传递职位数组功能

所以我张贴以下内容。

url=http%3A%2F%2Fwww.facebook.com%2Ftest&userId=680410999&location=Cardiff&lang=en_US&social=facebook 

我可以抓住它像这样从功能????

function login($_POST){ 

//then output the var her. 

$_POST['url']; etc 

} 

这是为了救我在做我的ajax.php文件

function login($_POST['url'],$_POST['userId'],$_POST['location'],$_POST['lang']){ 



    } 

以下任何帮助,请

+0

Concretise什么不与示例两个PLS一起工作? – mario

+0

我想你应该首先在PHP中学习[functions](http://www.php.net/manual/en/functions.arguments.php) – HerrSerker

回答

4

首先,你应该使用$_GET而不是$_POST。其次,您不需要将您的函数参数调用为$_GET。你可以这样做:

function login($array) 
{ 
    // do stuff with array 
} 

,然后调用函数以这种方式:

login($_GET); 

另外一个建议是阅读以下的报价,这是的实际参数正式的区别参数

形式参数是参数,因为它们在功能中已知的定义。实际参数(也称为参数)是调用者传递的 。

0

如果我unserstand你正确你想,你打电话给其传递一个数组(你的情况$_POST$_GET数组)作为参数的函数。

所以你的函数会是这个样子:

// not sure what you're doing with your login options but here's an example of getting them out of the array and putting them in variables - using the url as an example here... 
var url; 

function login($loginOptions) { 

    // set the url from the array 
    url = $loginOptions["url"]; 

    // do the same for all your other variable... 
} 

那么你会打电话给你的功能,像这样:

login($_POST); // or $_login($_GET); depending on what you're using 

就是这样!

0

你有其他答案应该为你解决这个问题。

还有一些建议,请记住清理代码中使用的任何$_POST$_GET数据。

例如,如果你在数据库中查询使用它,那么你将需要使用mysql_real_escape_string();,如果你是echo'ing数据,然后使用htmlentities();

0

我想你的意思是解析阵列的功能是什么为此,我会告诉你使用一个函数并将它与SESSION连接起来,如下所示。您可以使用$ _GET [$ var]来检索变量,但很难通过get方法处理,您可以使用$ _POST方法并将其与会话组合以保存数据,我将解释如何协作会话每页,以便您可以轻松检索您想要的变量。 下面的代码:

<?php 
    session_start(); 
    if(isset ($_POST['postedit'])) 
    { 
     $_SESSION['url'] = $_POST['urlsend']; 
     header("location:dua.php"); 
    } 
?> 
<html> 
    <body> 
     <form action="satu.php" method="POST"> 
      Name : <input type="text" name="urlsend"> <br> <br> 
      <input type="submit" name="postedit" value="SEND DATA"> 
     </form> 
    </body> 
</html> 

<?php 
session_start(); 
if(isset ($_SESSION['url'])) 
{ 
    //if data empty then will be redirected to the previous page 
    echo $_SESSION['url']; 
} 
?> 

我与动态数据创建的,甚至你可以选择使用此方法或其它方法。我希望你能够明白。