2011-06-15 51 views
0

我想發送數據到url並轉到url ...我使用index.php進行登錄並將發送數據發送到enter.php但我不知道如何在enter.php中使用post數據? 我使用cURL如何發送發佈數據到一個URL並轉到URL與PHP?

的index.php:

<? 
$c = curl_init(); 
curl_setopt($c , CURLOPT_URL , 'http://localhost/enter.php'); 
curl_setopt($c , CURLOPT_POST , 1); 
curl_setopt($c , CURLOPT_POSTFIELDS , 'name=Elmi&surname=Ehmedov'); 
curl_exec($c); curl_close($c); 
?> 

enter.php:

<? 
$nm = $_POST['name']; 
$snm = $_POST['surname']; 
echo $nm , $snm; 
?> 

謝謝你的建議。

+1

什麼問題? – Robik 2011-06-15 11:21:47

+0

不要去'enter.php'打開'index.php'裏面的'enter.php'。 – 2011-06-15 11:23:40

+0

你的代碼工作正常..你需要接下來發生什麼? – 2011-06-15 11:26:25

回答

0

將enter.php的代碼到index.php中

您需要檢查,如果用戶檢查/顯示「enter.php東西」

2

我想,如果我之前發送POST請求閱讀你的問題正確,那麼你需要一個AJAX電話來完成您的請求enter.php

既然你說話像你想處理您的輸入數據是在enter.php但用戶會看到index.php形式,當用戶提交表單應該將數據發佈到enter.php

請使用下面的代碼片段:

的index.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" language="javascript"></script> 

<script language="javascript"> 
$("#submit_form").submit(function() 
{ 
     //check the username exists or not from ajax 
     $.post("enter.php",{ name:$('#name').val(),surname:$('#surname').val(),rand:Math.random() } ,function(data) 
     { 
      if(data) //if correct login detail 
      { 
       $("#submit_response").html(data); 
      } 
     }); 

     alert("Problem in connecting your server."); 

     return false;//not to post the form physically 
}); 
</script> 

<!-- Show Message for AJAX response --> 
<div id="submit_response"></div> 

<form id="submit_form" action="javascript:login()" method="post"> 
<input name="name" type="text" id="name" value=""/> 
<input name="surname" type="text" id="surname" value=""/> 
<input type="submit" name="Submit" value="Submit"/> 
</form> 

enter.php

<?php 

$nm = $_POST['name']; 
$snm = $_POST['surname']; 
echo $nm.", ".$snm; 

?> 
+0

我想發送post數據,如 '

' 但你的代碼不會去enter.php中使用enter.php在index.php中。不要更改網址。 – 2011-06-15 12:09:12

+0

@Elmi Ehmedov請參閱最新的答案。我希望那是你想要的。 – 2011-06-17 06:41:58