If url variable is empty redirect to home page

我是研究僧i 提交于 2019-12-20 06:31:03

问题


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

回答1:


Try using empty():

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



回答2:


Another way:

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


来源:https://stackoverflow.com/questions/13848629/if-url-variable-is-empty-redirect-to-home-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!