如何解决php REDIRECTION ISSUE

时间:2014-11-27 07:52:10

标签: php

<?php
/* subject and email varialbles*/

$emailSbuject = 'Subscribe';
$webMaster = 'help@intaxfin.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/

$emailFeild = $_POST['email'];

// admin message body
$body= <<<EOD
Our new subscriber is $emailFeild

Email: $emailFeild 
EOD;

$textMessage = <<<EOD

        Thank you for subscribing us. Somebody will get back to you as soon as possible.

EOD;
    $headers = "From: $emailFeild\r\n";
    $header = "From: $noreply@example.com";
    $success = mail($webMaster,$emailSbuject,$body,$headers);
    $success1 = @mail($emailFeild,$emailSbuject2,$textMessage,$header);
    /*Result*/


    $theResults = <<<EOD
EOD;

echo  "$theResults";

header("Location: http://www.example.com/");
exit;
?>

我在每个页面下都有很多html页面。我有一个文本框和带有与之关联的php脚本的按钮。

我的问题是每当我输入我的电子邮件ID并点击该按钮时,它会将我重定向到主页www.example.com。我想留在那个确切的页面。

1 个答案:

答案 0 :(得分:0)

如果您在每个页面中显示表单,则只需添加以形成隐藏的输入并存储在此输入当前URL

<input type="hidden" name="redirect" value="<?php echo($_SERVER["REQUEST_URI"]); ?>" />

在您的脚本中检查此参数并重定向到网址

if (isset($_POST["redirect"]) && $_POST["redirect"] != "") {
  $redirect_to = $_POST["redirect"];
} else {
  $redirect_to = "/";
}
header("Location:" . $redirect_to);