如果url变量为空,则重定向到主页 [英] If url variable is empty redirect to home page

查看:49
本文介绍了如果url变量为空,则重定向到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使它正常工作!

我有一个view.php页面,该页面使用'ID'变量来检索数据库信息.

所以我的网址是这样的:

/view.php?id=23 

如果他们删除了网址的"23"部分,我试图让它将"用户重定向"到主页.

所以当您访问

/view.php?id=

应该:

if(isset($_GET['id']) == "") 
{ 
header('Location: /');
exit; }

如果我访问的话就可以

/view.php

解决方案

尝试使用 empty() :

if(empty($_GET['id'])) 
{ 
  header('Location: /');
  exit; 
}

I am not able to get this to work correctly!!

I have a view.php page that uses a variable of 'ID' to retrieve db info.

So my url is like this:

/view.php?id=23 

I am trying to get it to "redirect" the user to the home page if they erase the "23" part of the url.. ?

so when you visit

/view.php?id=

It should :

if(isset($_GET['id']) == "") 
{ 
header('Location: /');
exit; }

Works if I visit

/view.php

解决方案

Try using empty():

if(empty($_GET['id'])) 
{ 
  header('Location: /');
  exit; 
}

这篇关于如果url变量为空,则重定向到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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