如何添加一个GET变量到当前的URL? [英] How to add a GET variable to the current URL?

查看:113
本文介绍了如何添加一个GET变量到当前的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我想制作一些搜索页面,它需要一个get变量来对结果进行排序。因此,如果有人在没有GET变量的情况下进入页面,请重新加载页面并使其显示,例如您输入www.myweb.com/search并自动重新加载并更改为www.myweb.com/search/?sort=ascending(因为这个变量是必须的)。

I have a question, i want to make some search page, and it needs a get variable to sort the results. So if someone enters the page without that GET variable, reload the page and make it appear, for example you enter www.myweb.com/search and automatically reloads and changes to www.myweb.com/search/?sort=ascending (because that variable is necessary) .

我希望你明白我的意思,再见

I hope you understand me, good bye

推荐答案

我认为这将适用于您要做的事:

I think this will work for what you're looking to do:

if (empty($_GET['sort'])) {
    header('Location: ' . $_SERVER['REQUEST_URI'] . '?sort=ascending');
    exit();
}

这篇关于如何添加一个GET变量到当前的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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