2013-04-07 123 views
0

我有一个数组,用于在www.website1.com上存储用户登录信息。 当用户在www.website1.com上登录时,我需要将用户发送到www.website2.com以及他们的信息(用户名,密码等)。将阵列从一台服务器传递到另一台服务器

这是大干快上www.website1.com

$user = [ 
"user_name"=>$_POST["user_name"], 
"user_pass"=>$_POST["user_pass"], 
"from"=>$result["domain_id"] 
]; 
+0

为什么会这样下来投票?有人可以告诉我,我还有什么措辞可以这么做,所以我可以... – 2013-04-07 14:07:19

+0

“从一台服务器传递到另一台服务器”是什么意思? – Dogbert 2013-04-07 14:07:55

+0

我要重新编辑问题。 – 2013-04-07 14:08:40

回答

0

设置,您可以创建与动作指向要重定向用户的URL形式的阵列。在表单输入中包含要发送的数据。最后发送表格。这可以使用JavaScript完成,无需用户付出任何努力。

+0

我曾想到这一点。但不确定这将是安全的。 – 2013-04-07 14:19:24

+1

通过Internet发送密码不是。整个情况有点牙外,可以使用一些重新规划。 – 2013-04-07 14:20:43

+0

我认为使用POST过程的表单也需要使用cURL,请阅读:http:// stackoverflow。com/questions/12939156/submit-form-on-one-server-process-it-and-then-post-results-to-another-domain – daison12006013 2013-04-07 14:26:33

0

第一台服务器(www.website1.com):的index.php

<?php 
session_start(); 
$api_key = "ChowKiKo"; 
//First Server: index.php 
    if(isset($_SESSION['username'])) { 
      //-----------Server2 Validation-------------- 
     //Validate if the Server2's api_key is the same as my api_key 
     if(isset($_POST['api_key']) && $_POST['api_key'] == $api_key) { 
      //lets use methoding 
      if(isset($_POST['method']) && $_POST['method'] == 'getUserInfo') { 
       switch($_POST['method']) { 
        case 'getUserInfo': 
         $arr = array('username' => $_POST['username'], 'password' => $_POST['password'], 'from' => "http://www.website2.com"); 
         echo json_encode($arr); 
         break; 
        case 'getUserPost': 
         //mysql_query()...[code here and echo the value] 
         break; 
        case 'getUserFriends': 
         //the same thing here 
         break; 
       } 
      } 
     } 
    }else { 
     ?> 
     <html> 
      <head>Sample jSON with cURL</head> 
      <body> 
       <!-- Login Options --> 
       <form method="post" action="index.php"> 
        <input type="text" name="username" />[...] 
       </form> 
      </body> 
     </html> 
     <?php 
    } 
?> 

次服务器(www.website2.com):的index.php

<?php 
//Second Server: index.php 

     $api_key = 'ChowKiKo'; // Your API key. 
     $server1 = 'http://www.website1.com' 
     //$sessid = '9999your9999sess9999id'; // Your session ID. 

     //starting cURL 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_URL, $server1); 

     //prepare the field values being posted to the service 
     $data = array(
     'method' => '"getUserInfo"', 
     'api_key' => '"'. $api_key .'"', 
     //'sessid' => '"'. $sessid .'"', 
     //'arg1' => '"some value"', 
     //'arg2' => '"somevalue"', 
     //'argN'=>'"another value"', 
    ); 

     // POSTFIELD like GET process but processing internally with www.website1.com/index.php?method=getUserInfo&api_key=ChowKiko 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

     //make the request 
     $result = curl_exec($ch); 

     //print the jSON of the Server1, else it will return false. 
     echo $result; 
?> 
相关问题