【问题标题】:how can i redirect back to previous page after message sent from form [duplicate]从表单发送消息后,如何重定向回上一页[重复]
【发布时间】:2020-06-20 05:13:22
【问题描述】:

你好,我如何在 php 中返回上一页

<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. persons number is: ".$_POST['phone']." message is: ".$_POST['message'];
$headers = "From: ".$_POST['email'];

mail($to,$subject,$txt,$headers);


?>

【问题讨论】:

标签: php html forms redirect


【解决方案1】:

尝试使用phpheader函数。

例子是 PHP

header("Location: $_SERVER['HTTP_REFERER']");

PHP.net 的$_SERVER['HTTP_REFERER'] 在哪里

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

<?php

   $to = "email";

   $subject = "mailed from";

   $txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. 
           persons number is: ".$_POST['phone']." message is: 
           ".$_POST['message'];
   $headers = "From: ".$_POST['email'];

   mail($to,$subject,$txt,$headers);

   // Redirect after mail 
   header("Location: $_SERVER['HTTP_REFERER']");

?>

【讨论】:

  • header 没有工作, 这工作但是嗯......如何向它添加消息该消息是发送
【解决方案2】:

使用可以将其用于重定向 -

header("位置:pagename.php");

将 pagename.php 替换为您的页面。 将其放在邮件代码下方,以便在邮件发送后重定向。

【讨论】:

  • header 没有工作, 这工作但是嗯......如何向它添加消息该消息是发送
猜你喜欢
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
  • 1970-01-01
相关资源
最近更新 更多