在 PHP 会话期间重定向页面

发布于 2024-10-25 05:49:53 字数 60 浏览 6 评论 0原文

如何在提交按钮后重定向,注意:重定向到另一个页面必须携带上一个文件中的会话变量,然后显示在重定向的页面中。

How to redirect after the submit button, Note: The Redirection to another page must carry the session variables from previous file and then display in the redirected page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷月断魂刀 2024-11-01 05:49:53

通常您会在提交表单后重定向,这是因为,如果您点击 F5 按钮,您的表单会一次又一次地重新提交。

这是通过以下方式完成的,

  1. 设置会话值

  2. 使用标头函数重定向

    //如果按下提交按钮
    
    if(isset($_POST['提交'])){
    
    会话开始(); //也可以在它之前完成
    
    $_SESSION['somevalue'] = "somevalue";
    
    header('位置:somepage.php');
    }
    

Usually you redirect after submitting a form, it's because, if your hit F5 button, you form is resubmitted again and again.

This is done in follwing ways,

  1. Set session value

  2. Use header function to redirect

    //if the submit button is pressed
    
    if(isset($_POST['submit'])){
    
    session_start(); //also can be done before it
    
    $_SESSION['somevalue'] = "somevalue";
    
    header('location: somepage.php');
    }
    
九局 2024-11-01 05:49:53
header("location:somefile.php");

要携带会话变量,请确保您已在 somefile.php 中使用 session_start

session_start(); 在文件顶部调用该函数。

header("location:somefile.php");

To carry session variable make sure you have used session_start in somefile.php

session_start(); call that function at the top of file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文