I want to s开发者_JAVA技巧end post data to url and go to url... I use index.php
for login and send post data to enter.php
but I don't know how to use post data in enter.php?
I use 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;
?>
Thanks for advice.
I think if I am reading your question CORRECT then you need an AJAX call to complete your request to enter.php
.
Since you are talking like you want to process your input-data which is in enter.php
but user will see the form in index.php
and when user submits the form it should post the data to enter.php
.
Please use the following code snippet:
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;
?>
Put the code of enter.php into index.php
You need to check if the user send a post request before checking/showing the "enter.php stuff"
精彩评论