在页面重新加载时传递$ _GET参数 [英] Passing $_GET parameters on page reload

查看:84
本文介绍了在页面重新加载时传递$ _GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点,以便在页面重新加载时使用与上一页相同的$ _GET参数重定向我.现在,我正在尝试使用标头来实现此目的,但是当我提交表单时,变量$ id为空.

I am trying to make it so when the page reloads it redirects me with the same $_GET parameters as the previous page. Right now I am trying to use header to achieve this, but when I submit my form the variable $id is blank.

HTML表单

<form action = "." method ="post">
<input type = "text" name = "username">
<textarea name = "comments"></textarea>
<input type = "hidden" name = "action" value = "posts"> 
<input type = "submit" name = "submit" value = "Add Post">
</form>

重定向脚本

if ( empty( $_GET ) && !empty($_POST) ){
if($action == 'posts'){
if(!isset($_GET['thread'])){
$id = $_GET['thread'];
header('Location: ' . $_SERVER['REQUEST_URI'] .'?thread='.$id);
}   
}

感谢任何回复!

推荐答案

您的重定向脚本没有多大意义.试试吧,也许

Your redirect script doesn't make a lot of sense. Try this, maybe

if ( empty( $_GET ) && !empty($_POST) ){
    if(isset($_POST['thread'])){
        $id = $_POST['thread'];
        header('Location: ' . $_SERVER['REQUEST_URI'] .'?thread='.$id);
    }   
}

这篇关于在页面重新加载时传递$ _GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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