简体   繁体   English

在php中提交表单后如何加载上一页?

[英]How do I load the previous page after submitting a form in php?

I'm having trouble on how to redirect the page to the previous one after submitting a form in php.在 php 中提交表单后,我无法将页面重定向到上一个页面。 My site has this header that is used for all of my pages and it contains this "add" button which sends the form to my "add.php".我的网站有这个标题,用于我的所有页面,它包含这个“添加”按钮,将表单发送到我的“add.php”。 I'm not sure if using the header() function of php would solve it.我不确定使用 php 的 header() 函数是否可以解决它。

You shall try in php你应该试试php

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

Or via javascript或者通过javascript

header("location:javascript://history.go(-1)");

If you just want to navigate to the page after some action is done, you shall use action in your form.如果您只想在完成某些操作后导航到该页面,则应在表单中使用action

Here is the fully constructed function that you look for这是您要查找的完整构造函数

function goback()
{
    header("Location: {$_SERVER['HTTP_REFERER']}");
    exit;
}

goback();

Put the action='nameofyourpreviouspage.fileextention' inside your form tag.将 action='nameofyourpreviouspage.fileextention' 放在表单标签中。

Like this:像这样:

<form action="nameofyourpreviouspage.php" method="post">

try this尝试这个

header("location:pagename.php");

or或者

You shall try in php你应该试试 php

function return()
{
    header("Location: {$_SERVER['HTTP_REFERER']}");
    exit;
}
`<?php  

?>` or might u have problem with headers ob_start(); ?>` 或者你可能有标题 ob_start() 的问题; and ob_flush();和 ob_flush(); in begging and ending of the programme respectievely .it should work.thanks在分别乞求和结束程序。它应该工作。谢谢

只需将 $_SERVER["PHP_SELF"] 添加到 action 中,它是一个超级全局变量,它返回当前正在执行的脚本的文件名并将提交的表单数据发送到页面本身,而不是跳转到不同的页面

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM