如何将post数据发送到url并使用php转到url?

如何将post数据发送到url并使用php转到url?,php,curl,Php,Curl,我想将帖子数据发送到url并转到url。。。我使用index.php登录并将post数据发送到enter.php,但我不知道如何在enter.php中使用post数据? 我使用cURL index.php: <? $c = curl_init(); curl_setopt($c , CURLOPT_URL , 'http://localhost/enter.php'); curl_setopt($c , CURLOPT_POST , 1); curl_setopt($c , CURLOPT

我想将帖子数据发送到url并转到url。。。我使用
index.php
登录并将post数据发送到
enter.php
,但我不知道如何在enter.php中使用post数据? 我使用
cURL

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;
?>


谢谢您的建议。

将enter.php的代码放入index.php


在检查/显示“enter.php内容”之前,您需要检查用户是否发送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>

$(“#提交表格”)。提交(函数()
{
//从ajax检查用户名是否存在
$.post(“enter.php”,{name:$('#name').val(),姓氏:$('#姓氏').val(),rand:Math.random()),函数(数据)
{
if(data)//如果登录详细信息正确
{
$(“提交答复”).html(数据);
}
});
警报(“连接服务器时出现问题”);
return false;//不物理发布表单
});
enter.php

<?php

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

?>


不要进入
enter.php
打开
enter.php
index.php
。您的代码工作正常。接下来需要做什么?不要更改url。当我运行index.php时,使用enter.php,但不更改url。您想加载index.php,但将数据发布到enter.php,但不显示您实际发布到enter.php的用户?@Dan我想加载enter.php,并使用index.php中的发布数据。首先,我运行index.php。我想发送post数据,比如
,但您的代码不能进入enter.php。请在index.php中使用enter.php。不更改url。@Elmi Ehmedov请查看更新的答案。我希望这就是你想要的。