2011-06-15 48 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