PHP通过重定向传递数据 [英] PHP Pass Data with Redirect

查看:225
本文介绍了PHP通过重定向传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有发布数据的PHP重定向

PHP Redirect with Post Data

我是一名新手PHP程序员,正在尝试编写一个小型博客.

I am a newbie PHP programmer and trying to code a small blog.

我将解释我要做什么.

  • page1.php:具有博客中所有帖子的表格
  • page2.php:此页面具有一种表格,您可以在其中添加帖子

第2页发布到自身,然后处理数据,如果成功,则使用header()重定向回到显示该表的第1页.

Page 2 posts to itself and then processes the data, if it successful then uses header() to redirect back to page1 which shows the table.

现在我要做的是在表格上方的第1页上显示一条小消息,表明您的博客帖子已成功提交,但是我不确定如何将表格后的数据传递回第1页处理.

Now what I want to do is to be able to have a small message on page 1 above the table saying your blog post has been successfully submitted but I’m not sure how I can pass data back to page 1 after the form processing.

推荐答案

将其设置为$_SESSION值.

在第2页中:

$_SESSION['message'] = "Post successfully posted.";

在第1页中:

if(isset($_SESSION['message'])){
    echo $_SESSION['message']; // display the message
    unset($_SESSION['message']); // clear the value so that it doesn't display again
}

确保两个脚本的顶部都有session_start().

Make sure you have session_start() at the top of both scripts.

编辑:在if(isset($_SESSION['message']){

这篇关于PHP通过重定向传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆