2015-07-01 65 views
0

該代碼在同一臺服務器上正常工作。苗條的框架把帖子從其他服務器

我的問題是我怎麼能在一臺服務器上發佈更新?

因此,如果我張貼在www.domain1.comwww.domain2.com(api)emailadres,我該如何實現這一目標?我得到404頁面。

$app = new \Slim\Slim(); 

$app->put('/user/update/:id/', function($id) use($app){ 
global $connection; 
$app->response()->header("Content-Type", "application/json"); 

if($id && $id > 0){ 
    $result = $connection->query('SELECT * FROM `users` WHERE id = '.(int)$id.' ;'); 
}else{ 
    $result = array(); 
} 

if ($result) { 
    $post = $app->request()->put(); 
    $result = $connection->query("UPDATE `users` SET email = '".$_POST['email']."' WHERE id = $id;"); 
    echo json_encode(array(
    "status" => (bool)$result, 
    "message" => "User updated successfully" 
    )); 
} 
else{ 
    echo json_encode(array(
    "status" => false, 
    "message" => "User id $id does not exist" 
    )); 
} 
}); 

$app->run();?> 

形式:

<form action="" method="post"> 
    <input type="text" name="email" value=""/> 
    <input type="hidden" name="_METHOD" value="PUT"/> 
    <input type="submit" value="Update user"/> 
</form> 
+0

我不知道,我非常理解你說的話。對於我來說,你有「www.domain1.com」你的用戶可以使用html頁面訪問,「www.domain2.com」你有你的API。我對嗎? –

回答

0
if($_POST){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,"http://domain.com/user/update/7/"); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "email=".$_POST['email']."&_METHOD=put"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $server_output = curl_exec ($ch); 
    curl_close ($ch); 
} 

需要發送_method =把