PHP标题(位置:)重定向是否需要指向以"http://"开头的网站?

-1 html php redirect form-submit contact-form

我正在为我的客户做一些网络开发,我遇到了障碍.

**这是发生了什么:**

- 我们在我们的网站上有多个相同联系表格的副本,但我们希望每个人在完成后重定向到不同的目标网页,以便跟踪转化率.

- 在这个例子中,我正在处理about页面.当用户提交他们的更多信息请求时,理想情况下该页面将重定向到唯一的感谢页面(例如,www.sample.com/thank-you-webs.html); 然而,事实并非如此.

- 电子邮件将被完美发送,但重定向将永远不会发生.没有错误抛出 - 没有.

在我展示代码之前,这是我为了自己解决它而尝试过的:

- 我在表单发送输入的.php代码下面创建了一段HTML代码.据我所知,没有重定向,所以我显然还没有看到它.

- 我使用了呼叫"Header(位置:www.sample.com/thank-you-about.html)",但这也没有做任何事情.

- 我尝试过使用Javascript的"frame.location"方法,它似乎没有比php尝试更进一步.

- 我已经将源页面和目标页面保存为.php页面,因为使用.html扩展名是问题的根源; 同样的结果.

真的,我唯一能想到的是连接类型不满足Header()调用的要求.但是不会输出错误信息吗?

这是有问题的联系表格:

 <form id="contactForm" class="get-in-touch contact-form light" action="thank-you-about.php" method="post">
                        <input type="hidden" id="contact_nonce" name="contact_nonce" value="68592e213c"/><input type="hidden" name="" value="/"/>
                        <input type="hidden" name="contact-form-value" value="1"/>
                        <div class="iconic-input">
                            <input class="name" type="text" name="name" placeholder="Name*">
                            <i class="icons icon-user-1"></i>
                        </div>
                        <div class="iconic-input">
                            <input class="email" type="text" name="email" placeholder="Email*">
                            <i class="icons icon-email"></i>
                        </div>
                        <textarea class="msg" name="msg" placeholder="Message"></textarea>
                        <input type="submit" value="Send Message">
                        <div class="iconic-button">
                            <input type="reset" value="Clear">
                            <i class="icons icon-cancel-circle-1"></i>
                        </div>
                    </form>
Run Code Online (Sandbox Code Playgroud)

这是当前的.php文件,谢谢你-out.php:

    <?php

// Define some constants
define( "RECIPIENT_NAME", "Sample" );
define( "RECIPIENT_EMAIL", "writewoodcopy@gmail.com" );
define( "EMAIL_SUBJECT", "New request from site sample webpage" );

// Read the form values
$success = false;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$message = isset( $_POST['msg'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['msg'] ) : "";
$messageInterests = "";
$subject = "";
$currentURL = isset($_POST['current-URL'])? $_POST['current-URL'] : "";

//Parse checkboxes, include them in message body
$interestArray = $_POST['interest'];
if(!empty($interestArray)){
    $messageInterests .= "INFORMATION OF INTEREST:   ";
    $N = count($interestArray);
    for($i = 0; $i < $N; $i++)
    {
        $messageInterests .= "\r\n" . $interestArray[$i];
    }
    $subject .= $messageInterests . "\r\n \r\n";
}
else {
    $subject = "GENERAL INQUIRY \r\n \r\n";
}

$subject .= $message;
$message = $subject;

// If all values exist, send the email
if ( $senderName && $senderEmail && EMAIL_SUBJECT && $message ) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = "From: " . $senderName . " <" . $senderEmail . ">";
  mail( $recipient, EMAIL_SUBJECT, $message, $headers );
  header("Location: www.sample.com/thank-you-about.html"); /* Redirect browser */

}

?>
Run Code Online (Sandbox Code Playgroud)

编辑::在有人询问之前,我知道没有从这个特定的联系表单中解析复选框.它们在我的客户服务页面上派上用场,而一般查询则由about页面,联系我们页面和主页处理.

第二次编辑::所以,我修复了绝对URL问题; 但是,重定向问题仍然存在.谢谢大家这么耐心!

Ped*_*ito 5

PHP标题(位置:)重定向是否需要指向以"http://"开头的网站?

是的,如果您需要重定向到一个文件不同的域,你必须指定完整的绝对URL,这包括协议(http,https,等),基于的是,这不工作:

header("Location: www.sample.com/thank-you-about.html");
Run Code Online (Sandbox Code Playgroud)

使用:

header("Location: http://www.sample.com/thank-you-about.html");
Run Code Online (Sandbox Code Playgroud)

如果需要重定向到同一域中的文件,可以使用相对路径:

header("Location: thank-you-about.html"); //thank-you-about.html is located on the same dir as the current script
Run Code Online (Sandbox Code Playgroud)

要么

header("Location: /thank-you-about.html"); //thank-you-about.html is located on the root dir of the domain
Run Code Online (Sandbox Code Playgroud)

header()用于发送原始HTTP标头.有关HTTP标头的更多信息,请参阅» HTTP/1.1规范.

阅读有关php header()函数的更多信息.