所以我正在开发一个php Web应用程序。这是我正在处理的表格(trackit.php)。
<?php
function curlPOST($fields) {
$url = 'http://example.com/mailit4.php';
//url-ify the data for the POST^M
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
/*
$filename = 'leadids.txt';
$contents = file($filename);
$myfile = fopen("leadids.txt", "a") or die("Unable to open file!");
*/
$fields = array('lid' => $lid, 'list_id' => $list_id, 'phone'=> $phone);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Client Appreciation Weekend 2016</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/example" alt="example.com" width="600" height="133" style="margin-left:180px;" border="0" usemap="#Map" /></td>
</tr>
</table>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<form action="<?curlPOST($fields)?>" method="post" >
<tr>
<td>
<label>Phonenumber:</label>
</td>
<input type="hidden" name="lid" id="lid" size="40" value= "<?=$lid?>">
<input type="hidden" name="list_id" id="list_id" size="40" value= "<?=$list_id?>">
<td >
<input type="text" name="phonenumber" id="phonenumber" size="40" value= "<?=$phone?>"> <br>
</td>
</tr>
<tr align="center">
<td>
<input type="submit" name="btnSubmit" value="Submit Data">
</td>
</tr>
</form>
</table>
</body>
</html>
?>
我使用 curl post 将这三个值发布到 mailit4.php。当我单击提交时,它会调用该函数并运行另一台服务器上的 mailit4.php 脚本。一切正常,但是当我尝试将我的页面重定向到谢谢时.html它位于此服务器上(跟踪它在哪里.php)。它什么也没做。任何人都可以请问我如何重定向到谢谢.html
这是我的 mailit4 代码.php
<?php
$db = mysqli_connect('localhost', 'example', 'example', 'example');
$lid = $_POST['lid'];
$list_id = $_POST['list_id'];
$phone=$_POST['phone'];
$sql = "SELECT list_id FROM exampleWHERE lead_id=$lid";
$result = mysqli_query($db,$sql);
$value = mysqli_fetch_row($result);
if ($value[0] != $list_id){
$body = "Leadid " . $lid . " : " . $list_id . "'n'n";
$subject = "Zombie Drip:" . $lid . " : " . $list_id;
mail("example@gmail.com", $subject, $body);
}
$query = mysqli_query($db, "UPDATE example SET list_id=$list_id,called_since_last_reset='N',phone_number=$phone WHERE lead_id=$lid");
if($query){
header('Location: http://example.com/thanks.html/');
exit;
}
else{
$body = "Leadid " . $lid . " : " . $list_id . "'n'n";
$subject = "It could not update the example due to some reasons " .$query ;
mail("example@gmail.com", $subject, $body);
}
?>
谢谢
此代码无法正常工作,因为<form action="<?curlPOST($fields)?>" method="post" >
是错误的。
您没有回显curlPOST($fields)
因此,当您加载此页面时,您的mailit4.php
正在加载一次,并且此表单的操作设置为自身,就像<form action="" method="post" >
一样,并且您认为您的代码正在工作,因为每次提交时它都会调用此页面以及mailit4.php
。 您的正确操作将被<form action="" method="post" >
,并将此代码放在调用函数curlPOST
之后 if(!empty($_POST)) curlPOST($fields);
代码中的另一个问题是,
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
您的表单方法post
,并且您正在尝试通过get
捕获此数据
在您的mailit4.php
中,您使用邮件意味着您正在将数据发送到某个地方,这意味着数据已经刷新,然后您正在调用标头。 instate 使用file_get_contents()
来获取thanks.html
的内容,因为此脚本不会向您的浏览器输出任何内容。
请从您的mailit4中返回一些东西.php例如
If(mail($subject....))
{
echo "ok";
}
在你的卷曲函数中
If( $result == "ok" )
{
// redirect to thank you page
}
我给出的想法几乎没有描述,因为我正在从我的手机打字
希望对您有所帮助
谢谢